Dela via


FormRecognizerAsyncClient Class

  • java.lang.Object
    • com.azure.ai.formrecognizer.FormRecognizerAsyncClient

public final class FormRecognizerAsyncClient

This class provides an asynchronous client to connect to the Form Recognizer Azure Cognitive Service.

This client provides asynchronous methods to perform:

  1. Custom Form Analysis: Extraction and analysis of data from forms and documents specific to distinct business data and use cases. Use the custom trained model by passing its modelId into the beginRecognizeCustomForms(String modelId, Flux<ByteBuffer> form, long length) method.
  2. Prebuilt Model Analysis: Analyze receipts, business cards, invoices and other documents with supported prebuilt models Use the beginRecognizeReceipts(Flux<ByteBuffer> receipt, long length) method to recognize receipt information.
  3. Layout Analysis: Extraction and analysis of text, selection marks, tables, and bounding box coordinates, from forms and documents. Use beginRecognizeContent(Flux<ByteBuffer> form, long length) method too perform layout analysis.
  4. Polling and Callbacks: It includes mechanisms for polling the service to check the status of an analysis operation or registering callbacks to receive notifications when the analysis is complete.

Note: This client only supports V2_1 and lower. Recommended to use a newer service version, DocumentAnalysisClient and DocumentModelAdministrationClient.

Refer to the Migration guide to use API versions 2022-08-31 and up.

Service clients are the point of interaction for developers to use Azure Form Recognizer. FormRecognizerClient is the synchronous service client and FormRecognizerAsyncClient is the asynchronous service client. The examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation".

Sample: Construct a FormRecognizerClient with DefaultAzureCredential

The following code sample demonstrates the creation of a FormRecognizerAsyncClient, using the `DefaultAzureCredentialBuilder` to configure it.

FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildAsyncClient();

Further, see the code sample below to use AzureKeyCredential for client creation.

FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildAsyncClient();

Method Summary

Modifier and Type Method and Description
PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(Flux<ByteBuffer> businessCard, long length)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(Flux<ByteBuffer> businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

Recognizes business card data from documents using optical character recognition (OCR) and a prebuilt business card trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(Flux<ByteBuffer> form, long length)

Recognizes content/layout data using optical character recognition (OCR).

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(Flux<ByteBuffer> form, long length, RecognizeContentOptions recognizeContentOptions)

Recognizes content/layout data using optical character recognition (OCR).

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl)

Recognizes content/layout data from documents using optical character recognition (OCR).

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions)

Recognizes layout data from documents using optical character recognition (OCR) and a custom trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, Flux<ByteBuffer> form, long length)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, Flux<ByteBuffer> form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(Flux<ByteBuffer> identityDocument, long length)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(Flux<ByteBuffer> identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(Flux<ByteBuffer> invoice, long length)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(Flux<ByteBuffer> invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions)

Recognizes invoice data from documents using optical character recognition (OCR) and a prebuilt invoice trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(Flux<ByteBuffer> receipt, long length)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(Flux<ByteBuffer> receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions)

Recognizes receipt data from documents using optical character recognition (OCR) and a prebuilt receipt trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

Methods inherited from java.lang.Object

Method Details

beginRecognizeBusinessCards

public PollerFlux> beginRecognizeBusinessCards(Flux businessCard, long length)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a business card.

Note that the businessCard passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File businessCard = new File("{local/file_path/fileName.jpg}");
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(businessCard.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCards(buffer, businessCard.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedForm = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCard - The data of the document to recognize business card information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> that polls the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeBusinessCards

public PollerFlux> beginRecognizeBusinessCards(Flux businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

Recognizes business card data from documents using optical character recognition (OCR) and a prebuilt business card trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a business card.

Note that the businessCard passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File businessCard = new File("{local/file_path/fileName.jpg}");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(businessCard.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCards(buffer, businessCard.length(),
     new RecognizeBusinessCardsOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedForm = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCard - The data of the document to recognize business card information from.
length - The exact length of the data.
recognizeBusinessCardsOptions - The additional configurable RecognizeBusinessCardsOptions that may be passed when analyzing a business card.

Returns:

A PollerFlux<T,U> that polls the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeBusinessCardsFromUrl

public PollerFlux> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a business card.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

businessCardUrl - The source URL to the input business card.

Returns:

A PollerFlux<T,U> that polls the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeBusinessCardsFromUrl

public PollerFlux> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

Recognizes business card data using optical character recognition (OCR) and a prebuilt business card trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a business card.

Code sample

String businessCardUrl = "{business_card_url}";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl,
     new RecognizeBusinessCardsOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedBusinessCard = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCardUrl - The source URL to the input business card.
recognizeBusinessCardsOptions - The additional configurable RecognizeBusinessCardsOptions that may be passed when analyzing a business card.

Returns:

A PollerFlux<T,U> that polls the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeContent

public PollerFlux> beginRecognizeContent(Flux form, long length)

Recognizes content/layout data using optical character recognition (OCR).

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File form = new File("{local/file_path/fileName.jpg}");
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContent(buffer, form.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

form - The data of the form to recognize content information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> polls the recognize content operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.

beginRecognizeContent

public PollerFlux> beginRecognizeContent(Flux form, long length, RecognizeContentOptions recognizeContentOptions)

Recognizes content/layout data using optical character recognition (OCR).

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Content recognition supports auto language identification and multilanguage documents, so only provide a language code if you would like to force the documented to be processed as that specific language in the RecognizeContentOptions.

Code sample

File form = new File("{local/file_path/fileName.jpg}");
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContent(buffer, form.length(),
     new RecognizeContentOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setPollInterval(Duration.ofSeconds(5)))
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable -> formTable.getCells().forEach(recognizedTableCell ->
             System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

form - The data of the form to recognize content information from.
length - The exact length of the data.
recognizeContentOptions - The additional configurable RecognizeContentOptions that may be passed when recognizing content/layout on a form.

Returns:

A PollerFlux<T,U> polls the recognize content operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.

beginRecognizeContentFromUrl

public PollerFlux> beginRecognizeContentFromUrl(String formUrl)

Recognizes content/layout data from documents using optical character recognition (OCR).

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String formUrl = "{formUrl}";
 formRecognizerAsyncClient.beginRecognizeContentFromUrl(formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

formUrl - The URL of the form to analyze.

Returns:

A PollerFlux<T,U> that polls the recognize content operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.

beginRecognizeContentFromUrl

public PollerFlux> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions)

Recognizes layout data from documents using optical character recognition (OCR) and a custom trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Content recognition supports auto language identification and multilanguage documents, so only provide a language code if you would like to force the documented to be processed as that specific language in the RecognizeContentOptions.

Code sample

String formUrl = "{formUrl}";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContentFromUrl(formUrl,
     new RecognizeContentOptions().setPollInterval(Duration.ofSeconds(5)))
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

formUrl - The source URL to the input form.
recognizeContentOptions - The additional configurable RecognizeContentOptions that may be passed when recognizing content/layout on a form.

Returns:

A PollerFlux<T,U> that polls the recognized content/layout operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.

beginRecognizeCustomForms

public PollerFlux> beginRecognizeCustomForms(String modelId, Flux form, long length)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomForms(modelId, buffer, form.length())
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - The UUID string format custom trained model Id to be used.
form - The data of the form to recognize form information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> that polls the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeCustomForms

public PollerFlux> beginRecognizeCustomForms(String modelId, Flux form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the data passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomForms(modelId, buffer, form.length(),
     new RecognizeCustomFormsOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements)
         .setPollInterval(Duration.ofSeconds(5)))
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldName, formField) -> {
             System.out.printf("Field text: %s%n", fieldName);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - The UUID string format custom trained model Id to be used.
form - The data of the form to recognize form information from.
length - The exact length of the data.
recognizeCustomFormsOptions - The additional configurable RecognizeCustomFormsOptions that may be passed when recognizing custom forms.

Returns:

A PollerFlux<T,U> that polls the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeCustomFormsFromUrl

public PollerFlux> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model with or without labels.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - The UUID string format custom trained model Id to be used.
formUrl - The URL of the form to analyze.

Returns:

A PollerFlux<T,U> that polls the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeCustomFormsFromUrl

public PollerFlux> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

Recognizes form data from documents using optical character recognition (OCR) and a custom trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String formUrl = "{formUrl}";
 String modelId = "{model_id}";
 boolean includeFieldElements = true;

 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl,
     new RecognizeCustomFormsOptions()
         .setFieldElementsIncluded(includeFieldElements)
         .setPollInterval(Duration.ofSeconds(10)))
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - The UUID string format custom trained model Id to be used.
formUrl - The source URL to the input form.
recognizeCustomFormsOptions - The additional configurable RecognizeCustomFormsOptions that may be passed when recognizing custom forms.

Returns:

A PollerFlux<T,U> that polls the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeIdentityDocuments

public PollerFlux> beginRecognizeIdentityDocuments(Flux identityDocument, long length)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses. See here for fields found on an identity document.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the identityDocument passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File license = new File("local/file_path/license.jpg");
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(license.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocuments(buffer, license.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocument - The data of the document to recognize identity document information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> that polls the recognize identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeIdentityDocuments

public PollerFlux> beginRecognizeIdentityDocuments(Flux identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses. See here for fields found on an identity document.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Note that the identityDocument passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File licenseDocument = new File("local/file_path/license.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(licenseDocument.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocuments(buffer,
     licenseDocument.length(),
     new RecognizeIdentityDocumentOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocument - The data of the document to recognize identity document information from.
length - The exact length of the data.
recognizeIdentityDocumentOptions - The additional configurable RecognizeIdentityDocumentOptions that may be passed when analyzing an identity document.

Returns:

A PollerFlux<T,U> that polls the recognize identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeIdentityDocumentsFromUrl

public PollerFlux> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses. See here for fields found on an identity document.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String idDocumentUrl = "idDocumentUrl";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocumentsFromUrl(idDocumentUrl)
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocumentUrl - The source URL to the input identity document.

Returns:

A PollerFlux<T,U> that polls the recognize identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeIdentityDocumentsFromUrl

public PollerFlux> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

Analyze identity documents using optical character recognition (OCR) and a prebuilt model trained on identity documents model to extract key information from passports and US driver licenses. See here for fields found on an identity document.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String licenseDocumentUrl = "licenseDocumentUrl";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl,
     new RecognizeIdentityDocumentOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocumentUrl - The source URL to the input identity document.
recognizeIdentityDocumentOptions - The additional configurable RecognizeIdentityDocumentOptions that may be passed when analyzing an identity document.

Returns:

A PollerFlux<T,U> that polls the analyze identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeInvoices

public PollerFlux> beginRecognizeInvoices(Flux invoice, long length)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a invoice. Note that the invoice passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File invoice = new File("local/file_path/invoice.jpg");
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(invoice.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoices(buffer, invoice.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoice - The data of the document to recognize invoice information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeInvoices

public PollerFlux> beginRecognizeInvoices(Flux invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions)

Recognizes invoice data from documents using optical character recognition (OCR) and a prebuilt invoice trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a invoice. Note that the invoice passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

File invoice = new File("local/file_path/invoice.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(invoice.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoices(buffer,
     invoice.length(),
     new RecognizeInvoicesOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoice - The data of the document to recognize invoice information from.
length - The exact length of the data.
recognizeInvoicesOptions - The additional configurable RecognizeInvoicesOptions that may be passed when analyzing a invoice.

Returns:

A PollerFlux<T,U> that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeInvoicesFromUrl

public PollerFlux> beginRecognizeInvoicesFromUrl(String invoiceUrl)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a invoice.

Code sample

String invoiceUrl = "invoice_url";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoicesFromUrl(invoiceUrl)
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoiceUrl - The URL of the invoice to analyze.

Returns:

A PollerFlux<T,U> that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeInvoicesFromUrl

public PollerFlux> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions)

Recognizes invoice data using optical character recognition (OCR) and a prebuilt invoice trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String invoiceUrl = "invoice_url";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoicesFromUrl(invoiceUrl,
     new RecognizeInvoicesOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoiceUrl - The source URL to the input invoice.
recognizeInvoicesOptions - The additional configurable RecognizeInvoicesOptions that may be passed when analyzing a invoice.

Returns:

A PollerFlux<T,U> that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeReceipts

public PollerFlux> beginRecognizeReceipts(Flux receipt, long length)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a receipt.

Note that the receipt passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receipt - The data of the document to recognize receipt information from.
length - The exact length of the data.

Returns:

A PollerFlux<T,U> that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeReceipts

public PollerFlux> beginRecognizeReceipts(Flux receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions)

Recognizes receipt data from documents using optical character recognition (OCR) and a prebuilt receipt trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a receipt.

Note that the receipt passed must be replayable if retries are enabled (the default). In other words, the Flux must produce the same data each time it is subscribed to.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receipt - The data of the document to recognize receipt information from.
length - The exact length of the data.
recognizeReceiptsOptions - The additional configurable RecognizeReceiptsOptions that may be passed when analyzing a receipt.

Returns:

A PollerFlux<T,U> that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeReceiptsFromUrl

public PollerFlux> beginRecognizeReceiptsFromUrl(String receiptUrl)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

See here for fields found on a receipt.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receiptUrl - The URL of the receipt to analyze.

Returns:

A PollerFlux<T,U> that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

beginRecognizeReceiptsFromUrl

public PollerFlux> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions)

Recognizes receipt data using optical character recognition (OCR) and a prebuilt receipt trained model.

The service does not support cancellation of the long running operation and returns with an error message indicating absence of cancellation support.

Code sample

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receiptUrl - The source URL to the input receipt.
recognizeReceiptsOptions - The additional configurable RecognizeReceiptsOptions that may be passed when analyzing a receipt.

Returns:

A PollerFlux<T,U> that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.

Applies to