クライアント ライブラリを使用したドキュメント処理
このページでは、使い慣れたプログラミング言語で Document AI API を使用する方法を説明します。
始める前に
- Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Document AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Document AI > Document AI Administrator role to the service account.
To grant the role, find the Select a role list, then select Document AI > Document AI Administrator.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Document AI API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator) and the Project IAM Admin role (roles/resourcemanager.projectIamAdmin). Learn how to grant roles. -
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart. - Click Create and continue.
-
Grant the Document AI > Document AI Administrator role to the service account.
To grant the role, find the Select a role list, then select Document AI > Document AI Administrator.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALSto the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.
クライアント ライブラリをインストールする
C#
C# 開発環境の設定の詳細については、C# 開発環境設定ガイドをご覧ください。
Install-Package Google.Cloud.DocumentAI.V1 -Pre
Go
go get cloud.google.com/go/documentai
Java
Java 開発環境の設定の詳細については、Java 開発環境設定ガイドをご覧ください。
Maven を使用している場合は、次のものを pom.xml ファイルに追加します。BOM の詳細については、Google Cloud Platform ライブラリ BOM をご覧ください。
Gradle を使用している場合は、次のものを依存関係に追加します。
sbt を使用している場合は、次のものを依存関係に追加します。
Visual Studio Code または IntelliJ を使用している場合は、次の IDE プラグインでプロジェクトにクライアント ライブラリを追加できます。
プラグインでは、サービス アカウントのキー管理などの追加機能も提供されます。詳細は各プラグインのドキュメントをご覧ください。
Node.js
Node.js 開発環境の設定の詳細については、Node.js 開発環境設定ガイドをご覧ください。
npm install @google-cloud/documentai
PHP
composer require google/cloud-document-ai
Python
Python 開発環境の設定の詳細については、Python 開発環境設定ガイドをご覧ください。
pip install --upgrade google-cloud-documentai
Ruby
Ruby 開発環境の設定の詳細については、Ruby 開発環境設定ガイドをご覧ください。
gem install google-cloud-document_ai
ドキュメント処理
Document AI API を使用して、ローカル PDF ドキュメントから情報をリクエストします。次のサンプルを実行するには、まず UI でプロセッサを作成する必要があります。
コンソール
Google Cloud コンソールの Document AI セクションで、[プロセッサ] ページに移動します。
[プロセッサを作成] を選択します。
作成するプロセッサ タイプをリストからクリックします。
サイドの [プロセッサを作成] ウィンドウで、プロセッサ名を指定します。
リストからリージョンを選択します。
[作成] をクリックして、プロセッサを作成します。
プロセッサを作成してプロセッサ ID を取得したら、次のコードを実行して個々のドキュメント処理をリクエストします。
C#
詳細については、Document AI C# API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
C++
詳細については、Document AI C++ API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Go
詳細については、Document AI Go API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Java
詳細については、Document AI Java API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Node.js
詳細については、Document AI Node.js API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
PHP
詳細については、Document AI PHP API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Python
詳細については、Document AI Python API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
Ruby
詳細については、Document AI Ruby API リファレンス ドキュメントをご覧ください。
Document AI に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。
いかがでしたか
クリーンアップ
このクイックスタートで使用したリソースについて、Google アカウントに課金されないようにするには、次の手順を行います。
- 不要になったプロジェクトを Google Cloud console で削除します。
次のステップ
Document AI API クライアント ライブラリの詳細を確認する。