Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Invoices to CSV, entirely in the browser: the five walls I hit

Описание и применение

Пользователь создал решение для конвертации PDF‑счётов в CSV полностью в браузере, избегая загрузки файлов на сервер и соблюдая конфиденциальность клиентов.

Задача

Need to convert invoices to CSV without uploading PDFs to a server, respecting client privacy and avoiding per-document OCR costs.

Результат

The browser‑only solution runs in ~200 ms for text‑layer invoices and ~4 s for scanned invoices, eliminating server costs and privacy concerns.

Рабочий процесс

  • 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

Доказательства

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.

Источник

  • Дата записи: 2026-11-01T17:44:35.062Z