* * * GUIDES * * *
Extract text from invoices in Node.js.
Vendor PDFs, scanned paper, photographed bills — one client call turns each into text your code can parse. No native binaries, works on any Node 18+ runtime including serverless.
01 / INSTALL AND GET A KEY
npm install pennyocr
export PENNYOCR_API_KEY=pk_live_...02 / READ AN INVOICE
import PennyOCR from "pennyocr";
const client = new PennyOCR();
const result = await client.ocr("invoice.pdf"); // markdown, tables as HTML
console.log(result.text);03 / PLAIN TEXT + AMOUNT PARSING
const { text } = await client.ocr("invoice.pdf", { format: "text" });
const amounts = [...text.matchAll(/\d+\.\d{2}/g)].map((m) => parseFloat(m[0]));
const total = Math.max(...amounts);
console.log({ total });04 / IN AN API ROUTE (MULTER/BUSBOY NOT REQUIRED)
The SDK accepts Buffers and Blobs, so uploads pass straight through:
app.post("/parse-invoice", async (req, res) => {
const buf = await getRawBody(req); // however you collect the upload
const result = await client.ocr(buf, { filename: "upload.pdf" });
res.json({ pages: result.pages, text: result.text, cost: result.cost_usd });
});Multipage invoices are billed per page — a 3-page invoice costs $0.00225. Errors are deterministic: 402 means credits, 413 means too big, 422 means unreadable.