@@ -298,61 +298,60 @@ In this example, we'll analyze an invoice using the **prebuilt-invoice** model.
298
298
299
299
``` javascript
300
300
301
- // using the PrebuiltModels object, rather than the raw model ID, adds strong typing to the model's output
302
- const { PrebuiltModels } = require (" @azure/ai-form-recognizer" );
301
+ const { AzureKeyCredential , DocumentAnalysisClient } = require (" @azure/ai-form-recognizer" );
303
302
304
303
// set `<your-key>` and `<your-endpoint>` variables with the values from the Azure portal.
305
304
const key = " <your-key>" ;
306
305
const endpoint = " <your-endpoint>" ;
307
306
308
- // sample document
309
- const invoiceUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf" ;
310
307
311
- async function main () {
308
+ async function main () {
309
+ // sample document
310
+ const invoiceUrl = " https://raw.githubusercontent.com/Azure-Samples/cognitive-services-REST-api-samples/master/curl/form-recognizer/sample-invoice.pdf" ;
312
311
313
- const client = new DocumentAnalysisClient (endpoint, new AzureKeyCredential (key));
312
+ const client = new DocumentAnalysisClient (endpoint, new AzureKeyCredential (key));
314
313
315
- const poller = await client .beginAnalyzeDocument ( PrebuiltModels . Invoice , invoiceUrl);
314
+ const poller = await client .beginAnalyzeDocumentFromUrl ( " prebuilt-invoice " , invoiceUrl);
316
315
317
- const {
318
- documents: [result ]
319
- } = await poller .pollUntilDone ();
316
+ const {
317
+ documents: [result ]
318
+ } = await poller .pollUntilDone ();
320
319
321
- if (result) {
322
- const invoice = result .fields ;
323
-
324
- console .log (" Vendor Name:" , invoice .vendorName ? .value );
325
- console .log (" Customer Name:" , invoice .customerName ? .value );
326
- console .log (" Invoice Date:" , invoice .invoiceDate ? .value );
327
- console .log (" Due Date:" , invoice .dueDate ? .value );
328
-
329
- console .log (" Items:" );
330
- for (const {
331
- properties: item
332
- } of invoice .items ? .values ?? []) {
333
- console .log (" -" , item .productCode ? .value ?? " <no product code>" );
334
- console .log (" Description:" , item .description ? .value );
335
- console .log (" Quantity:" , item .quantity ? .value );
336
- console .log (" Date:" , item .date ? .value );
337
- console .log (" Unit:" , item .unit ? .value );
338
- console .log (" Unit Price:" , item .unitPrice ? .value );
339
- console .log (" Tax:" , item .tax ? .value );
340
- console .log (" Amount:" , item .amount ? .value );
341
- }
320
+ if (result) {
321
+ const invoice = result .fields ;
342
322
343
- console .log (" Subtotal:" , invoice .subTotal ? .value );
344
- console .log (" Previous Unpaid Balance:" , invoice .previousUnpaidBalance ? .value );
345
- console .log (" Tax:" , invoice .totalTax ? .value );
346
- console .log (" Amount Due:" , invoice .amountDue ? .value );
347
- } else {
348
- throw new Error (" Expected at least one receipt in the result." );
349
- }
350
- }
323
+ console .log (" Vendor Name:" , invoice .vendorName ? .value );
324
+ console .log (" Customer Name:" , invoice .customerName ? .value );
325
+ console .log (" Invoice Date:" , invoice .invoiceDate ? .value );
326
+ console .log (" Due Date:" , invoice .dueDate ? .value );
351
327
352
- main ().catch ((error ) => {
353
- console .error (" An error occurred:" , error);
354
- process .exit (1 );
355
- });
328
+ console .log (" Items:" );
329
+ for (const {
330
+ properties: item
331
+ } of invoice .items ? .values ?? []) {
332
+ console .log (" -" , item .productCode ? .value ?? " <no product code>" );
333
+ console .log (" Description:" , item .description ? .value );
334
+ console .log (" Quantity:" , item .quantity ? .value );
335
+ console .log (" Date:" , item .date ? .value );
336
+ console .log (" Unit:" , item .unit ? .value );
337
+ console .log (" Unit Price:" , item .unitPrice ? .value );
338
+ console .log (" Tax:" , item .tax ? .value );
339
+ console .log (" Amount:" , item .amount ? .value );
340
+ }
341
+
342
+ console .log (" Subtotal:" , invoice .subTotal ? .value );
343
+ console .log (" Previous Unpaid Balance:" , invoice .previousUnpaidBalance ? .value );
344
+ console .log (" Tax:" , invoice .totalTax ? .value );
345
+ console .log (" Amount Due:" , invoice .amountDue ? .value );
346
+ } else {
347
+ throw new Error (" Expected at least one receipt in the result." );
348
+ }
349
+ }
350
+
351
+ main ().catch ((error ) => {
352
+ console .error (" An error occurred:" , error);
353
+ process .exit (1 );
354
+ });
356
355
` ` `
357
356
358
357
**Run your application**
0 commit comments