עיבוד מסמכים באמצעות ספריות לקוח
בדף הזה מוסבר איך מתחילים להשתמש ב-Document AI API בשפת התכנות המועדפת עליכם.
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 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 מקומי. כדי להריץ את הדוגמאות הבאות, צריך קודם ליצור מעבד בממשק המשתמש.
המסוף
במסוף Google Cloud , בקטע Document AI, עוברים לדף Processors.
לוחצים על יצירת מעבד.
לוחצים על סוג המעבד שרוצים ליצור מתוך הרשימה.
בחלון הצדדי Create processor (יצירת מעבד), מציינים שם למעבד.
בוחרים את האזור מהרשימה.
לוחצים על יצירה כדי ליצור את המעבד.
אחרי שיוצרים מעבד ומקבלים את מזהה המעבד, מריצים את הקוד הבא כדי לבקש עיבוד של מסמך בודד:
C#
למידע נוסף, קראו את מאמרי העזרה של Document AI C# API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
C++
למידע נוסף, קראו את מאמרי העזרה של Document AI C++ API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Go
למידע נוסף, קראו את מאמרי העזרה של Document AI Go API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Java
למידע נוסף, קראו את מאמרי העזרה של Document AI Java API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Node.js
למידע נוסף, קראו את מאמרי העזרה של Document AI Node.js API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
PHP
למידע נוסף, קראו את מאמרי העזרה של Document AI PHP API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Python
למידע נוסף, קראו את מאמרי העזרה של Document AI Python API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
Ruby
למידע נוסף, קראו את מאמרי העזרה של Document AI Ruby API.
כדי לבצע אימות ב-Document AI, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.
איך היה?
הסרת המשאבים
כדי להימנע מחיובים בחשבון Google על המשאבים שבהם השתמשתם במדריך למתחילים הזה:
- אם אתם לא צריכים את הפרויקט, אתם יכולים להשתמש באפשרות Google Cloud console כדי למחוק אותו.