共用方式為


DocumentAnalysisClient class

用來與表格辨識器服務分析功能的互動用戶端。

範例:

表格辨識器服務和用戶端支援兩種驗證方式:

Azure Active Directory

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);

API 金鑰 (訂用帳戶金鑰)

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);

建構函式

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient從資源端點和靜態 API 金鑰建立實例 (KeyCredential) ,

範例:

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);
DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient從資源端點和 Azure 身分 TokenCredential 識別 建立實例。

@azure/identity如需使用 Azure Active Directory 進行驗證的詳細資訊,請參閱套件。

範例:

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);

方法

beginAnalyzeDocument(string, FormRecognizerRequestBody, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

使用其唯一識別碼所指定的模型,從輸入擷取資料。

此作業支援自訂和預先建置的模型。 例如,若要使用預先建置的發票模型,請提供模型識別碼「prebuilt-invoice」,或使用更簡單的預先建置配置模型,提供模型識別碼 「prebuilt-layout」。

AnalyzeResult 產生的欄位取決於用於分析的模型,而且任何擷取之檔欄位的值取決於模型中的檔案類型,如果有任何) 及其對應的欄位架構,則 (。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

import * as fs from "fs";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)
  entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
beginAnalyzeDocument<Result>(DocumentModel<Result>, FormRecognizerRequestBody, AnalyzeDocumentOptions<Result>)

使用具有已知強型別檔架構的模型,從輸入擷取資料, (DocumentModel) 。

AnalyzeResult 產生的欄位取決於用於分析的模型。 在 TypeScript 中,會從輸入 DocumentModel 的類型推斷這個方法多載的結果類型。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

如果提供的輸入是字串,則會將它視為要分析之檔位置的 URL。 如需詳細資訊,請參閱 beginAnalyzeDocumentFromUrl 方法。 使用 URL 時,最好使用該方法,而且只有在此方法中提供 URL 支援,才能提供回溯相容性。

import * as fs from "fs";

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
beginAnalyzeDocumentFromUrl(string, string, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

使用其唯一識別碼所指定的模型,從輸入擷取資料。

此作業支援自訂和預先建置的模型。 例如,若要使用預先建置的發票模型,請提供模型識別碼「prebuilt-invoice」,或使用更簡單的預先建置配置模型,提供模型識別碼 「prebuilt-layout」。

AnalyzeResult 產生的欄位取決於用於分析的模型,而且任何擷取之檔欄位的值取決於模型中的檔案類型,如果有任何) 及其對應的欄位架構,則 (。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
beginAnalyzeDocumentFromUrl<Result>(DocumentModel<Result>, string, AnalyzeDocumentOptions<Result>)

使用具有已知強型別檔架構的模型,從輸入擷取資料, (DocumentModel) 。

AnalyzeResult 產生的欄位取決於用於分析的模型。 在 TypeScript 中,會從輸入 DocumentModel 的類型推斷這個方法多載的結果類型。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

使用識別碼所指定的自訂分類器來分類檔。

這個方法會產生長時間執行的作業, (輪詢器) 最終會產生 AnalyzeResult 。 這與 beginAnalyzeDocumentbeginAnalyzeDocumentFromUrl 相同類型,但結果只會包含其欄位的小子集。 documents只會填入欄位和 pages 欄位,而且只會傳回最少的頁面資訊。 欄位 documents 將包含所有已識別檔及其 docType 分類為 的資訊。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

import * as fs from "fs";

const file = fs.createReadStream("path/to/file.pdf");

const poller = await client.beginClassifyDocument("<classifier ID>", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

使用識別碼所提供的自訂分類器,從 URL 分類檔。

這個方法會產生長時間執行的作業, (輪詢器) 最終會產生 AnalyzeResult 。 這與 beginAnalyzeDocumentbeginAnalyzeDocumentFromUrl 相同類型,但結果只會包含其欄位的小子集。 documents只會填入欄位和 pages 欄位,而且只會傳回最少的頁面資訊。 欄位 documents 將包含所有已識別檔及其 docType 分類為 的資訊。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// the URL must be publicly accessible
const url = "<file url>";

const poller = await client.beginClassifyDocument("<classifier ID>", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}

建構函式詳細資料

DocumentAnalysisClient(string, KeyCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient從資源端點和靜態 API 金鑰建立實例 (KeyCredential) ,

範例:

import { DocumentAnalysisClient, AzureKeyCredential } from "@azure/ai-form-recognizer";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new AzureKeyCredential("<api key>");

const client = new DocumentAnalysisClient(endpoint, credential);
new DocumentAnalysisClient(endpoint: string, credential: KeyCredential, options?: DocumentAnalysisClientOptions)

參數

endpoint

string

Azure 認知服務實例的端點 URL

credential
KeyCredential

包含認知服務實例訂用帳戶金鑰的 KeyCredential

options
DocumentAnalysisClientOptions

在用戶端中設定所有方法的選擇性設定

DocumentAnalysisClient(string, TokenCredential, DocumentAnalysisClientOptions)

DocumentAnalysisClient從資源端點和 Azure 身分 TokenCredential 識別 建立實例。

@azure/identity如需使用 Azure Active Directory 進行驗證的詳細資訊,請參閱套件。

範例:

import { DocumentAnalysisClient } from "@azure/ai-form-recognizer";
import { DefaultAzureCredential } from "@azure/identity";

const endpoint = "https://<resource name>.cognitiveservices.azure.com";
const credential = new DefaultAzureCredential();

const client = new DocumentAnalysisClient(endpoint, credential);
new DocumentAnalysisClient(endpoint: string, credential: TokenCredential, options?: DocumentAnalysisClientOptions)

參數

endpoint

string

Azure 認知服務實例的端點 URL

credential
TokenCredential

來自封裝的 @azure/identity TokenCredential 實例

options
DocumentAnalysisClientOptions

在用戶端中設定所有方法的選擇性設定

方法詳細資料

beginAnalyzeDocument(string, FormRecognizerRequestBody, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

使用其唯一識別碼所指定的模型,從輸入擷取資料。

此作業支援自訂和預先建置的模型。 例如,若要使用預先建置的發票模型,請提供模型識別碼「prebuilt-invoice」,或使用更簡單的預先建置配置模型,提供模型識別碼 「prebuilt-layout」。

AnalyzeResult 產生的欄位取決於用於分析的模型,而且任何擷取之檔欄位的值取決於模型中的檔案類型,如果有任何) 及其對應的欄位架構,則 (。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

import * as fs from "fs";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)
  entities, // extracted entities in the input's content, which are categorized (ex. "Location" or "Organization")
  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
function beginAnalyzeDocument(modelId: string, document: FormRecognizerRequestBody, options?: AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

參數

modelId

string

此用戶端資源內模型的唯一識別碼 (名稱)

document
FormRecognizerRequestBody

將會隨著要求上傳的FormRecognizerRequestBody

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

分析作業和輪詢器的選擇性設定

傳回

輪詢器 () 長時間執行的作業,最終會產生 AnalyzeResult

beginAnalyzeDocument<Result>(DocumentModel<Result>, FormRecognizerRequestBody, AnalyzeDocumentOptions<Result>)

使用具有已知強型別檔架構的模型,從輸入擷取資料, (DocumentModel) 。

AnalyzeResult 產生的欄位取決於用於分析的模型。 在 TypeScript 中,會從輸入 DocumentModel 的類型推斷這個方法多載的結果類型。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

如果提供的輸入是字串,則會將它視為要分析之檔位置的 URL。 如需詳細資訊,請參閱 beginAnalyzeDocumentFromUrl 方法。 使用 URL 時,最好使用該方法,而且只有在此方法中提供 URL 支援,才能提供回溯相容性。

import * as fs from "fs";

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

const file = fs.createReadStream("path/to/receipt.pdf");

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
function beginAnalyzeDocument<Result>(model: DocumentModel<Result>, document: FormRecognizerRequestBody, options?: AnalyzeDocumentOptions<Result>): Promise<AnalysisPoller<Result>>

參數

model

DocumentModel<Result>

代表要用於分析和預期輸出類型的模型DocumentModel

document
FormRecognizerRequestBody

將會隨著要求上傳的FormRecognizerRequestBody

options

AnalyzeDocumentOptions<Result>

分析作業和輪詢器的選擇性設定

傳回

Promise<AnalysisPoller<Result>>

長時間執行的作業 (輪詢器) ,最終 AnalyzeResult 會產生具有與輸入模型相關聯結果類型的檔

beginAnalyzeDocumentFromUrl(string, string, AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>)

使用其唯一識別碼所指定的模型,從輸入擷取資料。

此作業支援自訂和預先建置的模型。 例如,若要使用預先建置的發票模型,請提供模型識別碼「prebuilt-invoice」,或使用更簡單的預先建置配置模型,提供模型識別碼 「prebuilt-layout」。

AnalyzeResult 產生的欄位取決於用於分析的模型,而且任何擷取之檔欄位的值取決於模型中的檔案類型,如果有任何) 及其對應的欄位架構,則 (。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model, but you could use a custom model ID/name instead.
const poller = await client.beginAnalyzeDocument("prebuilt-receipt", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// The fields correspond to the model's document types and their field schemas. Refer to the Form Recognizer
// documentation for information about the document types and field schemas within a model, or use the `getModel`
// operation to view this information programmatically.
console.log("The type of this receipt is:", receipt?.["ReceiptType"]?.value);
function beginAnalyzeDocumentFromUrl(modelId: string, documentUrl: string, options?: AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

參數

modelId

string

此用戶端資源內模型的唯一識別碼 (名稱)

documentUrl

string

可從公用網際網路存取輸入檔的 URL (字串)

options

AnalyzeDocumentOptions<AnalyzeResult<AnalyzedDocument>>

分析作業和輪詢器的選擇性設定

傳回

輪詢器 () 長時間執行的作業,最終會產生 AnalyzeResult

beginAnalyzeDocumentFromUrl<Result>(DocumentModel<Result>, string, AnalyzeDocumentOptions<Result>)

使用具有已知強型別檔架構的模型,從輸入擷取資料, (DocumentModel) 。

AnalyzeResult 產生的欄位取決於用於分析的模型。 在 TypeScript 中,會從輸入 DocumentModel 的類型推斷這個方法多載的結果類型。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// See the `prebuilt` folder in the SDK samples (http://aka.ms/azsdk/formrecognizer/js/samples) for examples of
// DocumentModels for known prebuilts.
import { PrebuiltReceiptModel } from "./prebuilt-receipt.ts";

// the URL must be publicly accessible
const url = "<receipt document url>";

// The model that is passed to the following function call determines the type of the eventual result. In the
// example, we will use the prebuilt receipt model.
const poller = await client.beginAnalyzeDocument(PrebuiltReceiptModel, url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain lines and words
  tables, // extracted tables, organized into cells that contain their contents
  styles, // text styles (ex. handwriting) that were observed in the document
  keyValuePairs, // extracted pairs of elements  (directed associations from one element in the input to another)

  documents // extracted documents (instances of one of the model's document types and its field schema)
} = await poller.pollUntilDone();

// Extract the fields of the first document. These fields constitute a receipt, because we used the receipt model
const [{ fields: receipt }] = documents;

// Since we used the strongly-typed PrebuiltReceiptModel object instead of the "prebuilt-receipt" model ID
// string, the fields of the receipt are strongly-typed and have camelCase names (as opposed to PascalCase).
console.log("The type of this receipt is:", receipt.receiptType?.value);
function beginAnalyzeDocumentFromUrl<Result>(model: DocumentModel<Result>, documentUrl: string, options?: AnalyzeDocumentOptions<Result>): Promise<AnalysisPoller<Result>>

參數

model

DocumentModel<Result>

代表要用於分析和預期輸出類型的模型DocumentModel

documentUrl

string

可從公用網際網路存取輸入檔的 URL (字串)

options

AnalyzeDocumentOptions<Result>

分析作業和輪詢器的選擇性設定

傳回

Promise<AnalysisPoller<Result>>

輪詢器 () 長時間執行的作業,最終會產生 AnalyzeResult

beginClassifyDocument(string, FormRecognizerRequestBody, ClassifyDocumentOptions)

使用識別碼所指定的自訂分類器來分類檔。

這個方法會產生長時間執行的作業, (輪詢器) 最終會產生 AnalyzeResult 。 這與 beginAnalyzeDocumentbeginAnalyzeDocumentFromUrl 相同類型,但結果只會包含其欄位的小子集。 documents只會填入欄位和 pages 欄位,而且只會傳回最少的頁面資訊。 欄位 documents 將包含所有已識別檔及其 docType 分類為 的資訊。

範例

這個方法支援 FormRecognizerRequestBody) 格式 (可串流要求主體,例如 Node.JS ReadableStream 物件、瀏覽器 BlobArrayBuffer s。 本文的內容將會上傳至服務進行分析。

import * as fs from "fs";

const file = fs.createReadStream("path/to/file.pdf");

const poller = await client.beginClassifyDocument("<classifier ID>", file);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
function beginClassifyDocument(classifierId: string, document: FormRecognizerRequestBody, options?: ClassifyDocumentOptions): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

參數

classifierId

string

要用於分析的自訂分類器識別碼

document
FormRecognizerRequestBody

要分類的檔

options
ClassifyDocumentOptions

分類作業的選項

傳回

輪詢器 () 長時間執行的作業,最終會產生 AnalyzeResult

beginClassifyDocumentFromUrl(string, string, ClassifyDocumentOptions)

使用識別碼所提供的自訂分類器,從 URL 分類檔。

這個方法會產生長時間執行的作業, (輪詢器) 最終會產生 AnalyzeResult 。 這與 beginAnalyzeDocumentbeginAnalyzeDocumentFromUrl 相同類型,但結果只會包含其欄位的小子集。 documents只會填入欄位和 pages 欄位,而且只會傳回最少的頁面資訊。 欄位 documents 將包含所有已識別檔及其 docType 分類為 的資訊。

範例

這個方法支援從指定 URL 的檔案擷取資料。 表格辨識器服務會嘗試使用提交的 URL 下載檔案,因此必須可從公用網際網路存取 URL。 例如,SAS 權杖可用來授與 Azure 儲存體中 Blob 的讀取權限,而服務會使用 SAS 編碼的 URL 來要求檔案。

// the URL must be publicly accessible
const url = "<file url>";

const poller = await client.beginClassifyDocument("<classifier ID>", url);

// The result is a long-running operation (poller), which must itself be polled until the operation completes
const {
  pages, // pages extracted from the document, which contain only basic information for classifiers
  documents // extracted documents and their types
} = await poller.pollUntilDone();

// We'll print the documents and their types
for (const { docType } of documents) {
  console.log("The type of this document is:", docType);
}
function beginClassifyDocumentFromUrl(classifierId: string, documentUrl: string, options?: ClassifyDocumentOptions): Promise<AnalysisPoller<AnalyzeResult<AnalyzedDocument>>>

參數

classifierId

string

要用於分析的自訂分類器識別碼

documentUrl

string

要分類的檔 URL

傳回