Matterway
    Preparing search index...

    Function ocrDocument

    • Analyzes a document using OCR (Optical Character Recognition) and returns the extracted data.

      Parameters

      • ctx: Context

        The context object.

      • file: MwFile

        The file to be analyzed. Must be a PDF or an image file.

      • options: OcrOptions

        Options for the OCR process, including endpoint, key, and model.

      Returns Promise<AnalyzeResult<AnalyzedDocument>>

      The extracted data from the document.

      If the file type is not supported (neither PDF nor image).

      const files = await showUploadFile(ctx, {
      fileUploadTitle: 'Upload Files',
      uploadButton: 'Upload',
      fileUploadText: 'Please select file to upload.',
      minFileLimit: 1,
      maxFileLimit: 1,
      text: 'Please upload a file',
      });
      if (!files) {
      throw new Error('No files uploaded');
      }
      const options = {
      endpoint: 'https://{YOUR_ENDPOINT}.cognitiveservices.azure.com/',
      key: 'YOUR_KEY',
      };
      const data = await ocrDocument(ctx, file, options);
      console.log(data);