Getting an Invoice’s Text In the Browser: pdfjs Text Layer + tesseract OCR
AnyTool’s Invoice Field Extractor turns an uploaded invoice into structured data entirely on the device, and the first step is getting the text. For a digital (born-digital) PDF it reads the embedded text layer with pdfjs-dist: it walks every page’s positioned text items, buckets them by their Y coordinate to reconstruct lines and sorts each line by X so the reading order is preserved — this is fast and exact and needs no OCR. If a page carries little or no text (a scanned or image-only PDF), that page is rendered to a canvas at 2× scale and recognised with tesseract.js; an uploaded image (PNG, JPG, WebP, etc.) is OCR’d directly. Both pdfjs and tesseract.js load from the application’s own bundle — there is no CDN worker URL and no server — and a live progress bar reports the reading and OCR stages. The result is the invoice’s plain text, ready for parsing, obtained without the document ever leaving the browser.
- Digital PDFs use the pdfjs text layer — lines reconstructed from item X/Y positions, no OCR needed
- Scanned PDF pages are rendered to canvas at 2× and OCR’d with tesseract.js; images are OCR’d directly
- pdfjs and tesseract.js load from the app’s own bundle — no CDN, no server
- Per-page detection: a page with too little embedded text is sent to the OCR fallback automatically
- A progress indicator shows the reading and OCR stages while everything runs locally
