-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmultiReceiptsTutorial.js
More file actions
32 lines (27 loc) · 1020 Bytes
/
multiReceiptsTutorial.js
File metadata and controls
32 lines (27 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { setTimeout } = require("node:timers/promises");
const mindee = require("mindee");
async function parseReceipts(inputPath) {
// fill in your API key or add it as an environment variable
const mindeeClient = new mindee.v1.Client();
// Load a file from disk
const inputSource = new mindee.PathInput(
{ inputPath: inputPath }
);
const resp = await mindeeClient.parse(
mindee.v1.product.MultiReceiptsDetectorV1, inputSource
);
let receipts = await mindee.v1.extraction.extractReceipts(
inputSource, resp.document.inference
);
for (const receipt of receipts) {
const respReceipt = await mindeeClient.parse(
mindee.v1.product.ReceiptV5, receipt.asSource()
);
console.log(respReceipt.document.toString());
// optional: save to a file
receipt.saveToFile(`/tmp/receipt_p${receipt.pageId}_${receipt.receiptId}.pdf`);
// wait some time between requests as to not overload the server
await setTimeout(1000);
}
}
parseReceipts("/path/to/the/file.ext");