Invoices to CSV, entirely in the browser: the five walls I hit
Description and use
The author built a browser‑only PDF to CSV converter that uses pdf.js for text extraction and tesseract.js for OCR, avoiding server uploads and per‑document costs.
Problem
Need to convert invoices to CSV without uploading PDFs to a server, respecting client privacy and avoiding per-document OCR costs.
Outcome
The browser‑only solution runs in ~200 ms for text‑layer invoices and ~4 s for scanned invoices, eliminating server costs and privacy concerns.
Workflow
- Open PDF with pdf.js to obtain rendered page and text layer
- Count characters in text layer; if >120 use text layer directly
- If text layer insufficient, render page to canvas and run tesseract.js in a worker
- Group text spans into rows using a 6‑point tolerance
- Parse monetary amounts with a custom regex that handles various currency formats
- Export extracted data as CSV or XLSX
Evidence
pdf.js opens the file and hands back both the rendered page and, if it exists, the text layer with per-item coordinates.
If the text layer has enough characters, I parse those items directly — no OCR, no guessing, ~200ms for a normal invoice.
If it doesn't (a scan, a photo, a fax), I render the page to a canvas and run tesseract.js over it in a worker.
The naive approach is to group spans that share a y. That works until the first invoice where the vendor name and the invoice number sit 3 points apart vertically.
- Record date: 2026-11-01T17:44:35.062Z