Creates an instance of FormRecognizerClient.
Example usage:
import { FormRecognizerClient, AzureKeyCredential } from "@azure/ai-form-recognizer";
const client = new FormRecognizerClient(
"<service endpoint>",
new AzureKeyCredential("<api key>")
);
Url to an Azure Form Recognizer service endpoint
Used to authenticate requests to the service.
Url to an Azure Form Recognizer service endpoint
Recognizes content, including text and table structure from a form document.
This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const path = "./Invoice_7.pdf";
const readStream = fs.createReadStream(path);
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeContent(readStream, "application/pdf", {
onProgress: (state) => { console.log(`status: ${state.status}`); }
});
const pages = await poller.pollUntilDone();
Input document
Recognizes content, including text and table structure from a url to a form document.
This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const url = "<form document url>";
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeContentFromUrl(url, {
onProgress: (state) => { console.log(`status: ${state.status}`); }
});
const pages = await poller.pollUntilDone();
Url to a form document that is accessible from the service. Must be a valid, encoded URL to one of the following supported document types: PDF, JPEG, PNG, and TIFF.
Recognizes forms from a given document using a custom form model from training. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const path = "./Invoice_6.pdf";
const readStream = fs.createReadStream(path);
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", {
onProgress: (state) => { console.log(`status: ${state.status}`); }
});
const forms = await poller.pollUntilDone();
Id of the custom form model to use
Input form document
Recognizes forms from a url to a form document using a custom form model from training. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const url = "<form document url>";
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeCustomFormsFromUrl(modelId, url, {
onProgress: (state) => { console.log(`status: ${state.status}`); }
});
const forms = await poller.pollUntilDone();
Id of the custom form model to use
Url to a form document that is accessible from the service. Must be a valid, encoded URL to one of the following supported document types: PDF, JPEG, PNG, and TIFF.
Recognizes data from receipts using pre-built receipt model, enabling you to extract structure data from receipts such as merchant name, merchant phone number, transaction date, and more.
For a list of fields that are contained in the response, please refer to the "Supported fields" section at the following link: https://aka.ms/azsdk/formrecognizer/receiptfields
This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const path = "./contoso-allinone.jpg";
const readStream = fs.createReadStream(path);
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeReceipts(readStream, "image/jpeg", {
onProgress: (state) => { console.log(`status: ${state.status}`); }
});
const receipts = await poller.pollUntilDone();
if (!receipts || receipts.length <= 0) {
throw new Error("Expecting at lease one receipt in analysis result");
}
const receipt = receipts[0];
console.log("First receipt:");
const receiptTypeField = receipt.fields["ReceiptType"];
if (receiptTypeField.valueType === "string") {
console.log(` Receipt Type: '${receiptTypeField.value || "<missing>"}', with confidence of ${receiptTypeField.confidence}`);
}
const merchantNameField = receipt.fields["MerchantName"];
if (merchantNameField.valueType === "string") {
console.log(` Merchant Name: '${merchantNameField.value || "<missing>"}', with confidence of ${merchantNameField.confidence}`);
}
const transactionDate = receipt.fields["TransactionDate"];
if (transactionDate.valueType === "date") {
console.log(` Transaction Date: '${transactionDate.value || "<missing>"}', with confidence of ${transactionDate.confidence}`);
}
const itemsField = receipt.fields["Items"];
if (itemsField.valueType === "array") {
for (const itemField of itemsField.value || []) {
if (itemField.valueType === "object") {
const itemNameField = itemField.value!["Name"];
if (itemNameField.valueType === "string") {
console.log(` Item Name: '${itemNameField.value || "<missing>"}', with confidence of ${itemNameField.confidence}`);
}
}
}
}
const totalField = receipt.fields["Total"];
if (totalField.valueType === "number") {
console.log(` Total: '${totalField.value || "<missing>"}', with confidence of ${totalField.confidence}`);
}
Input document
Recognizes receipt information from a url using pre-built receipt model, enabling you to extract structure data from receipts such as merchant name, merchant phone number, transaction date, and more.
For a list of fields that are contained in the response, please refer to the "Supported fields" section at the following link: https://aka.ms/azsdk/formrecognizer/receiptfields
This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.
Example usage:
const url = "<url to the receipt document>";
const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
const poller = await client.beginRecognizeReceiptsFromUrl(
url, {
includeFieldElements: true,
onProgress: (state) => { console.log(`analyzing status: ${state.status}`); }
});
const receipts = await poller.pollUntilDone();
if (!receipts || receipts.length <= 0) {
throw new Error("Expecting at lease one receipt in analysis result");
}
const receipt = receipts[0];
console.log("First receipt:");
const receiptTypeField = receipt.fields["ReceiptType"];
if (receiptTypeField.valueType === "string") {
console.log(` Receipt Type: '${receiptTypeField.value || "<missing>"}', with confidence of ${receiptTypeField.confidence}`);
}
const merchantNameField = receipt.fields["MerchantName"];
if (merchantNameField.valueType === "string") {
console.log(` Merchant Name: '${merchantNameField.value || "<missing>"}', with confidence of ${merchantNameField.confidence}`);
}
const transactionDate = receipt.fields["TransactionDate"];
if (transactionDate.valueType === "date") {
console.log(` Transaction Date: '${transactionDate.value || "<missing>"}', with confidence of ${transactionDate.confidence}`);
}
const itemsField = receipt.fields["Items"];
if (itemsField.valueType === "array") {
for (const itemField of itemsField.value || []) {
if (itemField.valueType === "object") {
const itemNameField = itemField.value!["Name"];
if (itemNameField.valueType === "string") {
console.log(` Item Name: '${itemNameField.value || "<missing>"}', with confidence of ${itemNameField.confidence}`);
}
}
}
}
const totalField = receipt.fields["Total"];
if (totalField.valueType === "number") {
console.log(` Total: '${totalField.value || "<missing>"}', with confidence of ${totalField.confidence}`);
}
Url to a receipt document that is accessible from the service. Must be a valid, encoded URL to one of the following supported document types: PDF, JPEG, PNG, and TIFF.
Generated using TypeDoc
Client class for interacting with Azure Form Recognizer service.