BlogEngineering

Rules, Vision, or Both? What 7,500 Pages Taught Us About Finding Tables in PDFs

Hand-written table rules lost to a vision model at finding tables. They still earn their place, as measurements a learned model can weigh rather than as decisions.

A PDF has no table object, only drawing instructions, as we wrote in how to edit a table in a PDF. Papaya PDF must find a table and its rows and columns before you can edit it. We measured whether rules or a model should do that: "both, but not the way we had it".

The old approach

We used to find tables with a few dozen hand-tuned signals: crossing ruling lines form a grid, aligned word edges form a column, numbers sharing a right edge form a value column. Measuring it properly raised the question every team asks of its heuristics: is this the Bitter Lesson again?

The test

We used about 7,500 labeled public pages with 4,650 tables: ICDAR 2013 (government reports), FinTabNet (annual reports), PubTables-1M (scientific papers) and DocLayNet (manuals, filings and tenders). We added a small private set of real statements and bills, because that is what people bring us.

We compared three approaches:

  1. Rules alone, the engine as it was.
  2. Rules plus vision, added together: every rules table, plus what Heron, the layout model from IBM's Docling project, finds that the rules missed.
  3. A learned decision over both: rules and Heron propose, and a small gradient-boosted model trained on the labeled pages picks the real tables.

A table counts as found if it overlaps a labeled table by at least half and Papaya PDF can make it editable.

Rules lose as a detector

Rules aloneRules + vision, added togetherLearned decision over both
All public sets0.380.660.88
Annual reports (FinTabNet)0.280.650.91
Scientific papers0.510.780.97
Government reports0.750.820.94
Our statements and bills0.500.580.84

F1 score: the balance of finding real tables and not inventing fake ones. Higher is better.

On annual reports, the rules proposed a matching candidate for as few as a quarter of tables, and the hand-written logic accepted almost every candidate. It found the wrong things and kept them.

Adding vision finds more tables, but the rules' false tables remain and precision collapses: on our statements, over half its tables are not tables. The third column is what we ship towards.

Why not the vision model alone

Heron only says "there is a table here", not which characters belong to which cell, so it cannot edit anything.

The rules read the PDF's text layer: exact characters, positions and ruling lines. The engine builds cells from the file's real glyphs, so your edit looks like the author made it.

Against Heron's editable boxes alone, the hybrid still won by about a point overall and two on statements:

  • Tables only the rules see, usually tightly ruled grids, are kept.
  • Heron boxes the rules contradict, with no column alignment or repeating rows inside, are dropped.

Rows and columns

The other half of the job is the grid. Here the vision model is TableFormer, also from Docling, which reads rows, columns and merged cells from an image of the table.

Four views of the same annual-report table. Engine rules: a grid of 7 rows by 6 columns that stops at the Corporate row, leaves out the two-line total and the last row, and cuts the "Year Ended December 31," header into three cells. Layout model (Heron): one box around the whole table, confidence 0.98, no grid. Table structure model (TableFormer): 9 rows by 6 columns, with the year header as one cell spanning three columns and the two-line total kept as one row. Labeled truth: 9 rows by 6 columns, with the year header spanning three columns and each "% Change" header spanning two rows.
Figure 1. How each source sees one table from an annual report in FinTabNet: the rules stop two rows short and split the spanning header, the layout model only finds the box, and the table structure model's grid, merged header included, nearly matches what a person marked.
Engine (digital text)TableFormer (image)Better of the two, per table
Government reports (212 tables)0.610.660.76
Annual reports (785 tables)0.170.530.55

Share of tables whose grid groups every word into the right row and column.

TableFormer wins on annual reports, but it was trained on FinTabNet, its home turf. On government reports, new to both, they are close and right about different tables, so picking per table adds ten points.

Rules that survive

Annual reports put a lone "$" at the left of a value column, and the engine read it as its own column. Joining a currency symbol to its amount cut tables with extra columns from 74 to 17. That rule survives because it is a fact about typesetting, not a judgment about what is a table.

Statements often shade a column gray. A line placed midway between words, by the engine or TableFormer, lands a few points inside the gray, so the edited column disagrees with the visible one.

The PDF states that edge to a fraction of a point; an image only as finely as its resolution. The engine now snaps each line to a ruling line or shaded-cell edge within that line's own gap, or to the middle of the white seam between two shaded cells.

It never moves a line past its neighbour or through words, so row and column counts cannot change. The models decide how many lines; the file decides where.

What the Bitter Lesson says here

Rich Sutton argued that methods which learn from data, given more compute, beat human cleverness. Our numbers agree about decisions: every hand-tuned "table or not" threshold lost, and we are retiring them.

Much rule code was measuring: ruling lines, shared edges, numeric columns, structure tags. A screenshot cannot know two words are separate runs, or that a block is tagged as a table. Those measurements improve a learned model.

So: vision models propose, the engine measures and builds from the file's glyphs, and a learned model decides using both.

Frontier AI on born-digital tables

In our OCR tests, Claude put 99% of scanned table cells in the right row and column. For born-digital tables we tested 20 public pages with 26 labeled tables. Each Anthropic model got the page image and its words with positions, and was asked for every table's column and row lines.

Found tablesFalse tablesExact gridsRows rightColumns rightCost per 1,000 pages (est.)
Rules alone17 of 261146%62%79%free, on device
Heron + TableFormer26 of 26054%83%96%free, on device
Claude Haiku 5.526 of 26067%96%92%about $1
Claude Sonnet 5.526 of 26067%96%100%about $17
Claude Opus 5.526 of 26067%88%100%about $33

Costs are estimated from API prices for one call per page: about 3,300 tokens in (the page image and its word list) and about 1,000 out, including the model's reasoning. Batch processing halves them.

All three read grids better than anything else we measured, and Haiku matched Opus at about a fortieth of the price. The models see both picture and exact words, the same evidence our fusion combines.

Haiku on 120 more pages

Twenty pages is small, so we ran Haiku on 100 labeled pages and 20 with no tables.

Found tables (of 133)False tables on 20 empty pagesGrid puts every word in the right cellEditable table exactly right
Rules alone66839%38%
Heron + TableFormer123061%45%
Claude Haiku 5.5124061%53%

On grids alone the lead disappeared. The last column, what users feel, runs each answer through Papaya PDF's table lift, which builds the table from the file's text. Haiku's lines lift better because it sees the words and puts lines in the gaps; TableFormer's, drawn from pixels, sometimes graze a word.

That column also exposed a lift bug. Many annual reports draw a whole row as one text run, and the lift kept each run in one cell. It now splits a run at any space a column line crosses, raising exact tables from 42% to 45% for TableFormer and 47% to 53% for Haiku, as included above.

Giving the model the PDF too

On 40 pages we added the original PDF page to the image and word list.

Haiku 5.5, 40 pages, before the lift fixFound tables (of 48)Exact gridsRows rightEditable table exactly right
Image + words with positions4760%89%47%
The same, plus the PDF page4649%71%42%

It was worse and cost more. The PDF's text has no positions and comes in drawing order, and the model leaned on it over the word list, which is the useful part of the PDF here.

Why frontier AI is not the default

Not price. Privacy: the document would have to leave your device, which Papaya PDF never does by default. And speed and offline use: on-device models answer in a fraction of a second, offline.

Frontier AI has two roles: pre-labeling public training pages for people to check, and, for those who turn it on, breaking ties where the rules and on-device models disagree.

Why the on-device work still matters

  • The lead is modest: 53% against 45%, with equal grids and table finding.
  • The model needs the engine. Its lines become a table only through the lift, where every source loses the most.
  • Most documents should never leave your device. Frontier AI fits as an opt-in proposer and a cheap labeler whose answers train on-device models to close the gap.

On the same 120 pages, without asking any model again, we tried simple votes on each table's row and column counts:

grid fromEditable table exactly right
Rules alone38%
On-device model alone45%
Haiku alone53%
Rules + Haiku51%
Rules + on-device model + Haiku, two that agree win54%
Best possible pick of rules and the on-device model53%
Best possible pick of all three63%

Rules plus Haiku gains nothing: when they agree, Haiku was already right. Finding tables is saturated, since Haiku and Heron miss mostly the same ones.

The gain is in choosing the grid. The best per-table pick of rules and TableFormer would match Haiku on device, and a small trained grid chooser, which we are building next, might make it where a vote cannot.

Learned table evidence fusion

In machine-learning terms, this is late fusion with a stacked model on top.

Diagram: a PDF page feeds four sources. Engine rules read the file's own text, glyphs and ruling lines. A layout model (Heron) finds table boxes in the page image. A table structure model (TableFormer) reads rows and columns from a table's image. Frontier AI (Claude), opt-in and drawn dashed, returns a box and lines for each table. Learned model 1, the table finder, weighs the boxes from the rules, the layout model and frontier AI and decides which are tables. Learned model 2, the grid chooser, weighs the grids from the rules, the table structure model and frontier AI for each table kept. The engine then lifts the table from the file's own glyphs into an editable table.
Figure 2
  1. Base models propose. Rules, Heron and TableFormer each produce candidate tables and grids.
  2. Each candidate becomes a row of evidence: ruling lines, aligned edges, numeric columns, repeating row baselines, structure tags, Heron's confidence, whether proposers agree, and whether the engine can read a grid inside.
  3. Two small models decide. The table finder, a gradient-boosted decision-tree classifier, scores each box and keeps the best non-overlapping ones. The grid chooser picks whose rows and columns to trust. The finder is built and measured; the chooser is in training.

The alternative, early fusion, is one large network over pixels and text, as in LayoutLM. We chose late fusion because:

ReasonEvidence
Parts are replaceableSwapping Heron for Surya 2.5 on 311 pages: Heron proposed better (0.90 against 0.86 F1), yet fusion trained only with Heron still lifted Surya to 0.87. It learned from the PDF's evidence, not one model's quirks.
It runs on your deviceEach part is small; the decision model is tiny next to the vision models.
It needs few labelsThousands of labeled tables, not millions.

Trees handle missing evidence, such as no vision model installed, and show which signals they use. Logistic regression came within a point: the value is in learning the decision at all.

Where the rules still work alone

  • Tagged PDFs. A file that states its tables beats any guess.
  • No model on hand. Heron and TableFormer are downloads; before they arrive, or where unavailable, the engine's reading is instant.
  • Your files stay yours. The vision models also run on device; nothing here needs an upload.

Better labels

A learned decision is only as good as its labels, and public datasets cover papers and annual reports well but everyday documents badly. Our labeling tool outlines what the engine and models think is a table and asks one question at a time: is this one table, are these column lines right, is anything missing?

The labeling loop in four steps: the engine and models outline candidate tables on a page; a person answers one question at a time, such as one table, column lines right, or anything missing; a second person checks the page; and the answers train the next decision model, which feeds the next round of candidates
Figure 3. Every answer feeds back into the decision model, so each round of candidates starts from better judgment.

Verifying is several times faster and far less tiring than drawing, and two people check each page. The answers train the next decision model: rules measure, vision sees, people decide.

All the numbers

On public data unless noted.

ExperimentDataResult
Learned filter over rules' candidatesAll public sets, unseen documentsPrecision 30-72% → 94-98%; recall capped by rules proposing a match for only 23-78% of tables (Heron 83-100%)
Both propose, one decision7,482 pages, 4,653 tablesF1: rules 0.38, rules + Heron added 0.66, Heron editable boxes 0.87, learned decision 0.88
Heron vs Surya as vision model311 pagesHeron 0.90, Surya 0.86, fusion with Surya 0.87
Grids, engine vs TableFormer212 government, 785 annual-report tables0.61 vs 0.66 and 0.17 vs 0.53; best per-table pick 0.76 and 0.55
Engine fixes for statementsSame annual-report tablesJoining lone "$" and merging two-line headers: exact grids 0.14 → 0.17, correct column counts 40% → 55%
Frontier models20 pages, 26 tablesHaiku, Sonnet, Opus 5.5 found every table, 67% of grids exact
Haiku at scale120 pages, 20 without tablesExact lifts 53% vs 45% (Heron + TableFormer) and 38% (rules); grids tied at 61%; 0 false tables vs 8 from rules
Lift fixSame tablesExact lifts 42% → 45% (TableFormer lines), 47% → 53% (Haiku's)
Mixing sourcesSame tablesVote of rules, TableFormer, Haiku 54%; best pick of rules + TableFormer 53%, of all three 63%
PDF file added to Haiku's input40 pagesExact grids 60% → 49%