Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FormRecognizerClient

Package version

Client class for interacting with Azure Form Recognizer service.

Hierarchy

  • FormRecognizerClient

Index

Constructors

constructor

Properties

endpointUrl

endpointUrl: string

Url to an Azure Form Recognizer service endpoint

Methods

beginRecognizeContent

  • Recognizes content, including text and table structure from a form document.

    This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const path = "./Invoice_7.pdf";
    const readStream = fs.createReadStream(path);
    
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeContent(readStream, "application/pdf", {
      onProgress: (state) => { console.log(`status: ${state.status}`); }
    });
    
    await poller.pollUntilDone();
    const pages = poller.getResult();
    summary

    Recognizes content/layout information from a given document

    Parameters

    Returns Promise<ContentPollerLike>

beginRecognizeContentFromUrl

  • Recognizes content, including text and table structure from a url to a form document.

    This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const url = "<form document url>";
    
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeContentFromUrl(url, {
      onProgress: (state) => { console.log(`status: ${state.status}`); }
    });
    
    await poller.pollUntilDone();
    const pages = poller.getResult();
    summary

    Recognizes content/layout information from a url to a form document

    Parameters

    Returns Promise<ContentPollerLike>

beginRecognizeCustomForms

  • Recognizes forms from a given document using a custom form model from training. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const path = "./Invoice_6.pdf";
    const readStream = fs.createReadStream(path);
    
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeCustomForms(modelId, readStream, "application/pdf", {
      onProgress: (state) => { console.log(`status: ${state.status}`); }
    });
    await poller.pollUntilDone();
    const forms = poller.getResult();
    summary

    Recognizes form information from a given document using a custom form model.

    Parameters

    Returns Promise<FormPollerLike>

beginRecognizeCustomFormsFromUrl

  • Recognizes forms from a url to a form document using a custom form model from training. This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const url = "<form document url>";
    
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeCustomFormsFromUrl(modelId, url, {
      onProgress: (state) => { console.log(`status: ${state.status}`); }
    });
    await poller.pollUntilDone();
    const forms = poller.getResult();
    summary

    Recognizes form information from a url to a form document using a custom form model.

    Parameters

    • modelId: string

      Id of the custom form model to use

    • formUrl: string

      Url to an accessible form document ng", and "image/tiff";

    • Default value options: BeginRecognizeFormsOptions = {}

    Returns Promise<FormPollerLike>

beginRecognizeReceipts

  • Recognizes data from receipts using pre-built receipt model, enabling you to extract structure data from receipts such as merchant name, merchant phone number, transaction date, and more.

    For supported fields recognized by the service, please refer to https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-v2-preview/operations/GetAnalyzeReceiptResult.

    This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const path = "./contoso-allinone.jpg";
    const readStream = fs.createReadStream(path);
    
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeReceipts(readStream, "image/jpeg", {
      onProgress: (state) => { console.log(`status: ${state.status}`); }
    });
    
    await poller.pollUntilDone();
    const receipts = poller.getResult();
     if (!receipts || receipts.length <= 0) {
       throw new Error("Expecting at lease one receipt in analysis result");
     }
    
    const receipt = receipts[0];
    console.log("First receipt:");
    const receiptTypeField = receipt.recognizedForm.fields["ReceiptType"];
    if (receiptTypeField.valueType === "string") {
      console.log(`  Receipt Type: '${receiptTypeField.value || "<missing>"}', with confidence of ${receiptTypeField.confidence}`);
    }
    const merchantNameField = receipt.recognizedForm.fields["MerchantName"];
    if (merchantNameField.valueType === "string") {
      console.log(`  Merchant Name: '${merchantNameField.value || "<missing>"}', with confidence of ${merchantNameField.confidence}`);
    }
    const transactionDate = receipt.recognizedForm.fields["TransactionDate"];
    if (transactionDate.valueType === "date") {
      console.log(`  Transaction Date: '${transactionDate.value || "<missing>"}', with confidence of ${transactionDate.confidence}`);
    }
    const itemsField = receipt.recognizedForm.fields["Items"];
    if (itemsField.valueType === "array") {
      for (const itemField of itemsField.value || []) {
        if (itemField.valueType === "object") {
          const itemNameField = itemField.value!["Name"];
          if (itemNameField.valueType === "string") {
            console.log(`    Item Name: '${itemNameField.value || "<missing>"}', with confidence of ${itemNameField.confidence}`);
          }
        }
     }
    }
    const totalField = receipt.recognizedForm.fields["Total"];
    if (totalField.valueType === "number") {
      console.log(`  Total: '${totalField.value || "<missing>"}', with confidence of ${totalField.confidence}`);
    }
    summary

    Recognizes receipt information from a given document

    Parameters

    Returns Promise<ReceiptPollerLike>

beginRecognizeReceiptsFromUrl

  • Recognizes receipt information from a url using pre-built receipt model, enabling you to extract structure data from receipts such as merchant name, merchant phone number, transaction date, and more.

    For supported fields recognized by the service, please refer to https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-v2-preview/operations/GetAnalyzeReceiptResult.

    This method returns a long running operation poller that allows you to wait indefinitely until the operation is completed. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    Example usage:

    const url = "<url to the receipt document>";
    const client = new FormRecognizerClient(endpoint, new AzureKeyCredential(apiKey));
    const poller = await client.beginRecognizeReceiptsFromUrl(
      url, {
        includeTextDetails: true,
        onProgress: (state) => { console.log(`analyzing status: ${state.status}`); }
    });
    await poller.pollUntilDone();
    const receipts = poller.getResult();
     if (!receipts || receipts.length <= 0) {
       throw new Error("Expecting at lease one receipt in analysis result");
     }
    
    const receipt = receipts[0];
    console.log("First receipt:");
    const receiptTypeField = receipt.recognizedForm.fields["ReceiptType"];
    if (receiptTypeField.valueType === "string") {
      console.log(`  Receipt Type: '${receiptTypeField.value || "<missing>"}', with confidence of ${receiptTypeField.confidence}`);
    }
    const merchantNameField = receipt.recognizedForm.fields["MerchantName"];
    if (merchantNameField.valueType === "string") {
      console.log(`  Merchant Name: '${merchantNameField.value || "<missing>"}', with confidence of ${merchantNameField.confidence}`);
    }
    const transactionDate = receipt.recognizedForm.fields["TransactionDate"];
    if (transactionDate.valueType === "date") {
      console.log(`  Transaction Date: '${transactionDate.value || "<missing>"}', with confidence of ${transactionDate.confidence}`);
    }
    const itemsField = receipt.recognizedForm.fields["Items"];
    if (itemsField.valueType === "array") {
      for (const itemField of itemsField.value || []) {
        if (itemField.valueType === "object") {
          const itemNameField = itemField.value!["Name"];
          if (itemNameField.valueType === "string") {
            console.log(`    Item Name: '${itemNameField.value || "<missing>"}', with confidence of ${itemNameField.confidence}`);
          }
        }
     }
    }
    const totalField = receipt.recognizedForm.fields["Total"];
    if (totalField.valueType === "number") {
      console.log(`  Total: '${totalField.value || "<missing>"}', with confidence of ${totalField.confidence}`);
    }
    summary

    Recognizes receipt information from a given accessible url to input document

    Parameters

    Returns Promise<ReceiptPollerLike>

Generated using TypeDoc