Appearance
Function: ocrDocument()
ts
function ocrDocument(
ctx: Context,
file: MwFile,
options: OcrOptions): Promise<AnalyzeResult<AnalyzedDocument>>;Defined in: src/ai/ocr.tsx:41
Analyze a document with OCR and return the extracted data.
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Assistant context that holds secrets and configuration. |
file | MwFile | PDF or image file to analyze. |
options | OcrOptions | Endpoint, API key, and model for the OCR service. |
Returns
Promise<AnalyzeResult<AnalyzedDocument>>
The analyzed document result from Azure Document Intelligence.
Throws
If the file type is not a PDF or an image.
Example
ts
// Scan a restaurant receipt and pull out every line of text
const receipt = await getUploadedFile(ctx);
const data = await ocrDocument(ctx, receipt, {
endpoint: 'https://my-ocr.cognitiveservices.azure.com/',
key: 'ocr-key-123',
});
console.log(data.content);
// "Taco Palace\n2x Fish Taco $7.50\n1x Guac $3.00\nTotal: $18.00"