Class FormRecognizerClient

java.lang.Object
com.azure.ai.formrecognizer.FormRecognizerClient

public final class FormRecognizerClient extends Object
This class provides a synchronous client that contains all the operations that apply to Azure Form Recognizer. Operations allowed by the client are recognizing receipt, business card, invoice and identity document data from input documents, recognizing layout information and analyzing custom forms for predefined data.

Instantiating a synchronous Form Recognizer Client

 FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildClient();
 
See Also:
  • Method Details

    • beginRecognizeCustomFormsFromUrl

      public com.azure.core.util.polling.SyncPoller<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.

      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}";
      
       formRecognizerClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl).getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(formFieldMap -> formFieldMap.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 SyncPoller to poll the progress of the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If formUrl, modelId is null.
    • beginRecognizeCustomFormsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions, com.azure.core.util.Context context)
      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 analyzeFilePath = "{file_source_url}";
       String modelId = "{model_id}";
       boolean includeFieldElements = true;
      
       formRecognizerClient.beginRecognizeCustomFormsFromUrl(modelId, analyzeFilePath,
           new RecognizeCustomFormsOptions()
               .setFieldElementsIncluded(includeFieldElements)
               .setPollInterval(Duration.ofSeconds(10)), Context.NONE)
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(formFieldMap -> formFieldMap.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 options that may be passed when recognizing custom forms.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller to poll the progress of the recognize custom form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If formUrl, modelId is null.
    • beginRecognizeCustomForms

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, InputStream 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.

      Code sample

       File form = new File("{local/file_path/fileName.jpg}");
       String modelId = "{custom_trained_model_id}";
       byte[] fileContent = Files.readAllBytes(form.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
      
           formRecognizerClient.beginRecognizeCustomForms(modelId, targetStream, form.length())
               .getFinalResult()
               .stream()
               .map(RecognizedForm::getFields)
               .forEach(formFieldMap -> formFieldMap.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 SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If form, modelId is null.
    • beginRecognizeCustomForms

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, InputStream form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions, com.azure.core.util.Context context)
      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

       File form = new File("{local/file_path/fileName.jpg}");
       String modelId = "{custom_trained_model_id}";
       boolean includeFieldElements = true;
       byte[] fileContent = Files.readAllBytes(form.toPath());
      
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
           formRecognizerClient.beginRecognizeCustomForms(modelId, targetStream, form.length(),
               new RecognizeCustomFormsOptions()
                   .setContentType(FormContentType.IMAGE_JPEG)
                   .setFieldElementsIncluded(includeFieldElements)
                   .setPollInterval(Duration.ofSeconds(10)), Context.NONE)
               .getFinalResult()
               .stream()
               .map(RecognizedForm::getFields)
               .forEach(formFieldMap -> formFieldMap.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.
      recognizeCustomFormsOptions - The additional configurable options that may be passed when recognizing custom forms.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If form, modelId is null.
    • beginRecognizeContentFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<FormPage>> 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 = "{form_url}";
       formRecognizerClient.beginRecognizeContentFromUrl(formUrl)
           .getFinalResult()
           .forEach(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()
                   .stream()
                   .flatMap(formTable -> formTable.getCells().stream())
                   .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
           });
       
      Parameters:
      formUrl - The URL of the form to analyze.
      Returns:
      A SyncPoller that polls the recognize content form operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If formUrl is null.
    • beginRecognizeContentFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions, com.azure.core.util.Context context)
      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.

      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 options.

      Code sample

       String formPath = "{file_source_url}";
       formRecognizerClient.beginRecognizeContentFromUrl(formPath,
           new RecognizeContentOptions()
               .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
           .getFinalResult()
           .forEach(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()
                   .stream()
                   .flatMap(formTable -> formTable.getCells().stream())
                   .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
           });
       
      Parameters:
      formUrl - The source URL to the input form.
      recognizeContentOptions - The additional configurable options that may be passed when recognizing content/layout on a form.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller that polls the recognize layout operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If formUrl is null.
    • beginRecognizeContent

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(InputStream form, long length)
      Recognizes layout data 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

       File form = new File("{local/file_path/fileName.pdf}");
       byte[] fileContent = Files.readAllBytes(form.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
           formRecognizerClient.beginRecognizeContent(targetStream, form.length())
               .getFinalResult()
               .forEach(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()
                       .stream()
                       .flatMap(formTable -> formTable.getCells().stream())
                       .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 SyncPoller that polls the recognize content operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If form is null.
    • beginRecognizeContent

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(InputStream form, long length, RecognizeContentOptions recognizeContentOptions, com.azure.core.util.Context context)
      Recognizes content/layout data from the provided document 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

      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 options.

      Code sample

       File form = new File("{file_source_url}");
       byte[] fileContent = Files.readAllBytes(form.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
      
           for (FormPage formPage : formRecognizerClient.beginRecognizeContent(targetStream, form.length(),
               new RecognizeContentOptions()
                   .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
               .getFinalResult()) {
               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()
                   .stream()
                   .flatMap(formTable -> formTable.getCells().stream())
                   .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 options that may be passed when recognizing content/layout on a form.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller that polls the recognize content operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of FormPage.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If form is null.
    • beginRecognizeReceiptsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl)
      Recognizes receipt data from document 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 receiptUrl = "{file_source_url}";
       formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl)
           .getFinalResult()
           .forEach(recognizedReceipt -> {
               Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
               FormField merchantNameField = recognizedFields.get("MerchantName");
               if (merchantNameField != null) {
                   if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                       String merchantName = merchantNameField.getValue().asString();
                       System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                           merchantName, merchantNameField.getConfidence());
                   }
               }
      
               FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
               if (merchantPhoneNumberField != null) {
                   if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                       String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                       System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                           merchantAddress, merchantPhoneNumberField.getConfidence());
                   }
               }
      
               FormField transactionDateField = recognizedFields.get("TransactionDate");
               if (transactionDateField != null) {
                   if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                       LocalDate transactionDate = transactionDateField.getValue().asDate();
                       System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                           transactionDate, transactionDateField.getConfidence());
                   }
               }
      
               FormField receiptItemsField = recognizedFields.get("Items");
               if (receiptItemsField != null) {
                   System.out.printf("Receipt Items: %n");
                   if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                       List<FormField> receiptItems = receiptItemsField.getValue().asList();
                       receiptItems.stream()
                           .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                           .map(formField -> formField.getValue().asMap())
                           .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                               if ("Quantity".equals(key)) {
                                   if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                       Float quantity = formField.getValue().asFloat();
                                       System.out.printf("Quantity: %f, confidence: %.2f%n",
                                           quantity, formField.getConfidence());
                                   }
                               }
                           }));
                   }
               }
           });
       
      Parameters:
      receiptUrl - The URL of the receipt to analyze.
      Returns:
      A SyncPoller to poll the progress of the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If receiptUrl is null.
    • beginRecognizeReceiptsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions, com.azure.core.util.Context context)
      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

      Code sample

       String receiptUrl = "{receipt_url}";
       formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl,
           new RecognizeReceiptsOptions()
               .setLocale(FormRecognizerLocale.EN_US)
               .setPollInterval(Duration.ofSeconds(5))
               .setFieldElementsIncluded(true), Context.NONE)
           .getFinalResult()
           .forEach(recognizedReceipt -> {
               Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
               FormField merchantNameField = recognizedFields.get("MerchantName");
               if (merchantNameField != null) {
                   if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                       String merchantName = merchantNameField.getValue().asString();
                       System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                           merchantName, merchantNameField.getConfidence());
                   }
               }
      
               FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
               if (merchantPhoneNumberField != null) {
                   if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                       String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                       System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                           merchantAddress, merchantPhoneNumberField.getConfidence());
                   }
               }
      
               FormField transactionDateField = recognizedFields.get("TransactionDate");
               if (transactionDateField != null) {
                   if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                       LocalDate transactionDate = transactionDateField.getValue().asDate();
                       System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                           transactionDate, transactionDateField.getConfidence());
                   }
               }
      
               FormField receiptItemsField = recognizedFields.get("Items");
               if (receiptItemsField != null) {
                   System.out.printf("Receipt Items: %n");
                   if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                       List<FormField> receiptItems = receiptItemsField.getValue().asList();
                       receiptItems.stream()
                           .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                           .map(formField -> formField.getValue().asMap())
                           .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                               if ("Quantity".equals(key)) {
                                   if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                       Float quantity = formField.getValue().asFloat();
                                       System.out.printf("Quantity: %f, confidence: %.2f%n",
                                           quantity, formField.getConfidence());
                                   }
                               }
                           }));
                   }
               }
           });
       
      Parameters:
      receiptUrl - The source URL to the input receipt.
      recognizeReceiptsOptions - The additional configurable options that may be passed when analyzing a receipt.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller to poll the progress of the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If receiptUrl is null.
    • beginRecognizeReceipts

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(InputStream receipt, long length)
      Recognizes data from the provided document data using optical character recognition (OCR) and a prebuilt trained receipt 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

       File receipt = new File("{receipt_url}");
       byte[] fileContent = Files.readAllBytes(receipt.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
      
           formRecognizerClient.beginRecognizeReceipts(targetStream, receipt.length()).getFinalResult()
               .forEach(recognizedReceipt -> {
                   Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
                   FormField merchantNameField = recognizedFields.get("MerchantName");
                   if (merchantNameField != null) {
                       if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                           String merchantName = merchantNameField.getValue().asString();
                           System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                               merchantName, merchantNameField.getConfidence());
                       }
                   }
      
                   FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
                   if (merchantPhoneNumberField != null) {
                       if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                           String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                           System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                               merchantAddress, merchantPhoneNumberField.getConfidence());
                       }
                   }
      
                   FormField transactionDateField = recognizedFields.get("TransactionDate");
                   if (transactionDateField != null) {
                       if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                           LocalDate transactionDate = transactionDateField.getValue().asDate();
                           System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                               transactionDate, transactionDateField.getConfidence());
                       }
                   }
      
                   FormField receiptItemsField = recognizedFields.get("Items");
                   if (receiptItemsField != null) {
                       System.out.printf("Receipt Items: %n");
                       if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                           List<FormField> receiptItems = receiptItemsField.getValue().asList();
                           receiptItems.stream()
                               .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                               .map(formField -> formField.getValue().asMap())
                               .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                                   if ("Quantity".equals(key)) {
                                       if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                           Float quantity = formField.getValue().asFloat();
                                           System.out.printf("Quantity: %f, confidence: %.2f%n",
                                               quantity, formField.getConfidence());
                                       }
                                   }
                               }));
                       }
                   }
               });
       }
       
      Parameters:
      receipt - The data of the receipt to recognize receipt information from.
      length - The exact length of the data.
      Returns:
      A SyncPoller that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If receipt is null.
    • beginRecognizeReceipts

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(InputStream receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions, com.azure.core.util.Context context)
      Recognizes data from the provided document data using optical character recognition (OCR) and a prebuilt trained receipt 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

       File receipt = new File("{local/file_path/fileName.jpg}");
       boolean includeFieldElements = true;
       byte[] fileContent = Files.readAllBytes(receipt.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
           for (RecognizedForm recognizedForm : formRecognizerClient
               .beginRecognizeReceipts(targetStream, receipt.length(),
                   new RecognizeReceiptsOptions()
                       .setContentType(FormContentType.IMAGE_JPEG)
                       .setFieldElementsIncluded(includeFieldElements)
                       .setLocale(FormRecognizerLocale.EN_US)
                       .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
               .getFinalResult()) {
               Map<String, FormField> recognizedFields = recognizedForm.getFields();
               FormField merchantNameField = recognizedFields.get("MerchantName");
               if (merchantNameField != null) {
                   if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                       String merchantName = merchantNameField.getValue().asString();
                       System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                           merchantName, merchantNameField.getConfidence());
                   }
               }
               FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
               if (merchantPhoneNumberField != null) {
                   if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                       String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                       System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                           merchantAddress, merchantPhoneNumberField.getConfidence());
                   }
               }
               FormField transactionDateField = recognizedFields.get("TransactionDate");
               if (transactionDateField != null) {
                   if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                       LocalDate transactionDate = transactionDateField.getValue().asDate();
                       System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                           transactionDate, transactionDateField.getConfidence());
                   }
               }
               FormField receiptItemsField = recognizedFields.get("Items");
               if (receiptItemsField != null) {
                   System.out.printf("Receipt Items: %n");
                   if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                       List<FormField> receiptItems = receiptItemsField.getValue().asList();
                       receiptItems.stream()
                           .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                           .map(formField -> formField.getValue().asMap())
                           .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                               if ("Quantity".equals(key)) {
                                   if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                       Float quantity = formField.getValue().asFloat();
                                       System.out.printf("Quantity: %f, confidence: %.2f%n",
                                           quantity, formField.getConfidence());
                                   }
                               }
                           }));
                   }
               }
           }
       }
       
      Parameters:
      receipt - The data of the receipt to recognize receipt information from.
      length - The exact length of the data.
      recognizeReceiptsOptions - The additional configurable options that may be passed when analyzing a receipt.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller that polls the recognize receipt operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If receipt is null.
    • beginRecognizeBusinessCardsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)
      Recognizes business card data from document 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}";
       formRecognizerClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl)
           .getFinalResult()
           .forEach(recognizedBusinessCard -> {
               Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
               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.
      Returns:
      A SyncPoller to poll the progress of the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If businessCardUrl is null.
    • beginRecognizeBusinessCardsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, com.azure.core.util.Context context)
      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.

      Code sample

       String businessCardUrl = "{business_card_url}";
       formRecognizerClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl,
           new RecognizeBusinessCardsOptions()
               .setFieldElementsIncluded(true), Context.NONE)
           .setPollInterval(Duration.ofSeconds(5)).getFinalResult()
           .forEach(recognizedBusinessCard -> {
               Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
               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 options that may be passed when analyzing a business card.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller to poll the progress of the recognize business card operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If businessCardUrl is null.
    • beginRecognizeBusinessCards

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(InputStream businessCard, long length)
      Recognizes business card data from the provided document data using optical character recognition (OCR) and a prebuilt trained business card 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

       File businessCard = new File("{local/file_path/fileName.jpg}");
       byte[] fileContent = Files.readAllBytes(businessCard.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
           formRecognizerClient.beginRecognizeBusinessCards(targetStream, businessCard.length()).getFinalResult()
               .forEach(recognizedBusinessCard -> {
                   Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
                   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 business card to recognize business card information from.
      length - The exact length of the data.
      Returns:
      A SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If businessCard is null.
    • beginRecognizeBusinessCards

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(InputStream businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, com.azure.core.util.Context context)
      Recognizes business card data from the provided document data using optical character recognition (OCR) and a prebuilt trained business card 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

       File businessCard = new File("{local/file_path/fileName.jpg}");
       boolean includeFieldElements = true;
       byte[] fileContent = Files.readAllBytes(businessCard.toPath());
       try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
           for (RecognizedForm recognizedForm : formRecognizerClient.beginRecognizeBusinessCards(targetStream,
               businessCard.length(),
               new RecognizeBusinessCardsOptions()
                   .setContentType(FormContentType.IMAGE_JPEG)
                   .setFieldElementsIncluded(includeFieldElements),
               Context.NONE).setPollInterval(Duration.ofSeconds(5))
               .getFinalResult()) {
               Map<String, FormField> recognizedFields = recognizedForm.getFields();
               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 business card to recognize business card information from.
      length - The exact length of the data.
      recognizeBusinessCardsOptions - The additional configurable options that may be passed when analyzing a business card.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If businessCard is null.
    • beginRecognizeInvoicesFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl)
      Recognizes invoice data from document 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 an invoice.

      Code sample

       String invoiceUrl = "invoice_url";
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeInvoicesFromUrl(invoiceUrl)
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 document to analyze.
      Returns:
      A SyncPoller to poll the progress of the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If invoiceUrl is null.
    • beginRecognizeInvoicesFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions, com.azure.core.util.Context context)
      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

      Code sample

       String invoiceUrl = "invoice_url";
       boolean includeFieldElements = true;
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeInvoicesFromUrl(invoiceUrl,
           new RecognizeInvoicesOptions()
               .setFieldElementsIncluded(includeFieldElements),
           Context.NONE).setPollInterval(Duration.ofSeconds(5))
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 document.
      recognizeInvoicesOptions - The additional configurable options that may be passed when analyzing an invoice.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller to poll the progress of the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If invoiceUrl is null.
    • beginRecognizeInvoices

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(InputStream invoice, long length)
      Recognizes data from the provided document data using optical character recognition (OCR) and a prebuilt trained invoice 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

       File invoice = new File("local/file_path/invoice.jpg");
       ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(invoice.toPath()));
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeInvoices(inputStream, invoice.length())
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 invoice to recognize invoice related information from.
      length - The exact length of the data.
      Returns:
      A SyncPoller that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If invoice is null.
    • beginRecognizeInvoices

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(InputStream invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions, com.azure.core.util.Context context)
      Recognizes data from the provided document data using optical character recognition (OCR) and a prebuilt trained invoice 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

       File invoice = new File("local/file_path/invoice.jpg");
       boolean includeFieldElements = true;
       // Utility method to convert input stream to Byte buffer
       ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(invoice.toPath()));
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeInvoices(inputStream,
           invoice.length(),
           new RecognizeInvoicesOptions()
               .setContentType(FormContentType.IMAGE_JPEG)
               .setFieldElementsIncluded(includeFieldElements),
           Context.NONE)
           .setPollInterval(Duration.ofSeconds(5))
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 invoice to recognize invoice related information from.
      length - The exact length of the data.
      recognizeInvoicesOptions - The additional configurable options that may be passed when analyzing a invoice.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller that polls the recognize invoice operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If invoice is null.
    • beginRecognizeIdentityDocumentsFromUrl

      public com.azure.core.util.polling.SyncPoller<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. 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";
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl)
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 dateOfBirthField = recognizedFields.get("DateOfBirth");
               if (dateOfBirthField != null) {
                   if (FieldValueType.DATE == dateOfBirthField.getValue().getValueType()) {
                       LocalDate dateOfBirth = dateOfBirthField.getValue().asDate();
                       System.out.printf("Date of Birth: %s, confidence: %.2f%n",
                           dateOfBirth, dateOfBirthField.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 SyncPoller to poll the progress of the recognize identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If identityDocumentUrl is null.
    • beginRecognizeIdentityDocumentsFromUrl

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, com.azure.core.util.Context context)
      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.
       formRecognizerClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl,
           new RecognizeIdentityDocumentOptions()
               .setFieldElementsIncluded(includeFieldElements),
           Context.NONE).setPollInterval(Duration.ofSeconds(5))
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 options that may be passed when analyzing an identity document.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller to poll the progress of the recognize identity document operation until it has completed, has failed, or has been cancelled. The completed operation returns a list of RecognizedForm.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If identityDocumentUrl is null.
    • beginRecognizeIdentityDocuments

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(InputStream 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

      Code sample

       File license = new File("local/file_path/license.jpg");
       ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(license.toPath()));
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeIdentityDocuments(inputStream, license.length())
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 identity document to recognize identity document information from.
      length - The exact length of the data.
      Returns:
      A SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If identityDocument is null.
    • beginRecognizeIdentityDocuments

      public com.azure.core.util.polling.SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(InputStream identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, com.azure.core.util.Context context)
      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

       File licenseDocument = new File("local/file_path/license.jpg");
       boolean includeFieldElements = true;
       // Utility method to convert input stream to Byte buffer
       ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(licenseDocument.toPath()));
       // if training polling operation completed, retrieve the final result.
       formRecognizerClient.beginRecognizeIdentityDocuments(inputStream,
           licenseDocument.length(),
           new RecognizeIdentityDocumentOptions()
               .setContentType(FormContentType.IMAGE_JPEG)
               .setFieldElementsIncluded(includeFieldElements),
           Context.NONE)
           .setPollInterval(Duration.ofSeconds(5))
           .getFinalResult()
           .stream()
           .map(RecognizedForm::getFields)
           .forEach(recognizedFields -> {
               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 dateOfBirthField = recognizedFields.get("DateOfBirth");
               if (dateOfBirthField != null) {
                   if (FieldValueType.DATE == dateOfBirthField.getValue().getValueType()) {
                       LocalDate dateOfBirth = dateOfBirthField.getValue().asDate();
                       System.out.printf("Date of Birth: %s, confidence: %.2f%n",
                           dateOfBirth, dateOfBirthField.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 identity document to recognize information from.
      length - The exact length of the data.
      recognizeIdentityDocumentOptions - The additional configurable options that may be passed when analyzing an identity document.
      context - Additional context that is passed through the HTTP pipeline during the service call.
      Returns:
      A SyncPoller 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.
      Throws:
      FormRecognizerException - If recognize operation fails and the AnalyzeOperationResult returned with an OperationStatus.FAILED.
      NullPointerException - If identityDocument is null.