Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions example/invoiceSplitterCustomSplitsTutorial.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
const { Client, product, imageOperations, PathInput } = require("mindee");
const { setTimeout } = require("node:timers/promises");
const mindee = require("mindee");

async function parseInvoicesWithCustomSplitsThreshold(customSplits) {
async function parseInvoicesWithCustomSplitsThreshold(inputPath, customSplits) {
// fill in your API key or add it as an environment variable
const mindeeClient = new Client();
const mindeeClient = new mindee.v1.Client();

// Load a file from disk
const inputSource = new PathInput(
{ inputPath: "/path/to/the/file.ext" }
const inputSource = new mindee.PathInput(
{ inputPath: inputPath }
);

let invoices = await imageOperations.extractInvoices(inputSource, customSplits);
let invoices = await mindee.v1.extraction.extractInvoices(inputSource, customSplits);
for (const invoice of invoices) {
// optional: save the documents locally
invoice.saveToFile(`/tmp/invoice_p_${invoice.pageIdMin}-${invoice.pageIdMax}.pdf`);
const respInvoice = await mindeeClient.parse(product.InvoiceV4, invoice.asSource());
const respInvoice = await mindeeClient.parse(
mindee.v1.product.InvoiceV4, invoice.asSource()
);
console.log(respInvoice.document.toString());
await setTimeout(1000); // wait some time between requests as to not overload the server
// wait some time between requests as to not overload the server
await setTimeout(1000);
}

}

const customSplits = [[0, 1], [1, 2]];

parseInvoicesWithCustomSplitsThreshold(customSplits);
parseInvoicesWithCustomSplitsThreshold(
"/path/to/the/file.ext",
customSplits
);
27 changes: 16 additions & 11 deletions example/invoiceSplitterTutorial.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
const { Client, product, imageOperations, PathInput } = require("mindee");
const { setTimeout } = require("node:timers/promises");
const mindee = require("mindee");

async function parseInvoices() {
async function parseInvoices(inputPath) {
// fill in your API key or add it as an environment variable
const mindeeClient = new Client();
const mindeeClient = new mindee.v1.Client();

// Load a file from disk
const inputSource = new PathInput(
{ inputPath: "/path/to/the/file.ext" }
const inputSource = new mindee.PathInput(
{ inputPath: inputPath }
);

const resp = await mindeeClient.enqueueAndParse(
product.InvoiceSplitterV1, inputSource
mindee.v1.product.InvoiceSplitterV1,
inputSource
);
let invoices = await mindee.v1.extraction.extractInvoices(
inputSource, resp.document.inference
);
let invoices = await imageOperations.extractInvoices(inputSource, resp.document.inference);
for (const invoice of invoices) {
// optional: save the documents locally
invoice.saveToFile(`/tmp/invoice_p_${invoice.pageIdMin}-${invoice.pageIdMax}.pdf`);
const respInvoice = await mindeeClient.parse(product.InvoiceV4, invoice.asSource());
const respInvoice = await mindeeClient.parse(
mindee.v1.product.InvoiceV4, invoice.asSource()
);
console.log(respInvoice.document.toString());
await setTimeout(1000); // wait some time between requests as to not overload the server
// wait some time between requests as to not overload the server
await setTimeout(1000);
}

}

parseInvoices();
parseInvoices("/path/to/the/file.ext");
32 changes: 20 additions & 12 deletions example/multiReceiptsTutorial.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
const { Client, product, imageOperations, PathInput } = require("mindee");
const { setTimeout } = require("node:timers/promises");
const mindee = require("mindee");

async function parseReceipts() {
async function parseReceipts(inputPath) {
// fill in your API key or add it as an environment variable
const mindeeClient = new Client();
const mindeeClient = new mindee.v1.Client();

// Load a file from disk
const inputSource = new PathInput(
{ inputPath: "/path/to/the/file.ext" }
const inputSource = new mindee.PathInput(
{ inputPath: inputPath }
);

const resp = await mindeeClient.parse(product.MultiReceiptsDetectorV1, inputSource);
let receipts = await imageOperations.extractReceipts(inputSource, resp.document.inference);
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(product.ReceiptV5, receipt.asSource());
const respReceipt = await mindeeClient.parse(
mindee.v1.product.ReceiptV5, receipt.asSource()
);
console.log(respReceipt.document.toString());
receipt.saveToFile(`/tmp/receipt_p${receipt.pageId}_${receipt.receiptId}.pdf`); //optional: save to a file
await setTimeout(1000); // wait some time between requests as to not overload the server
}
// 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();
parseReceipts("/path/to/the/file.ext");
Loading