The problem I kept running into: a financial report where a subtotal on page 8 is wrong, but nobody spots it until the numbers get aggregated into a spreadsheet and something doesn’t reconcile.
I wanted a tool that could ingest any PDF with tables and tell me which totals don’t add up. The constraint: no template, no column mapping UI, no server. Every byte in the browser.
What it does
Upload a PDF. The tool:
- Extracts all text items with their x/y coordinates from each page via pdfjs-dist
- Clusters items by y-position into rows (within a 4px snap tolerance)
- Detects which rows are “total” or “subtotal” rows by keyword matching
- For each total row, identifies numeric columns and sums the data rows above it (back to the previous header or total)
- Compares computed sum to stated total — flags differences above a 0.1% tolerance
The hard part: coordinate-based table detection
PDF text items don’t know they’re in a table. The structure is: a stream of (string, x, y, width) tuples. I have to infer table structure purely from spatial relationships.
The approach:
- Snap y-coordinates to a 4px grid to handle sub-pixel jitter between lines
- Cluster x-positions of numeric cells to find “column anchors” — positions that consistently have numbers
- A column anchor that appears in 2+ data rows becomes a verifiable column
- For each total row, look up the value at each column anchor and compare to the sum above
This breaks on rotated text, multi-column layouts, and cells that span multiple columns. But it catches the common case — section subtotals in financial reports, grand totals in expense sheets.
Stack
- Next.js 14, static export on Cloudflare Workers
- pdfjs-dist for text extraction (CDN worker, no bundling)
- All detection and arithmetic runs in the browser
Freemium
3 PDFs/month tracked in localStorage. Paid plan unlocks unlimited and CSV export ($9/month).
Live at: https://compare-lab.xyz/pdf-table-checker/
If you work with tabular PDFs regularly and there’s a document structure this approach would miss, I’d like to know.
답글 남기기