#1949·xberg

fix(ocr): OCR drops a table when a split amount column has rule marks in it

Author: tobocop2Created Sep 29, 2026Updated Sep 29, 2026
LabelsbugP1

Description

On a scanned page, one right-aligned amount column can split into two adjacent columns by digit width. The OCR table cleanup has a merge that joins such a pair back into one column when each row fills only one of the two tracks and every value is an amount (#1649).

OCR also reads the page's horizontal rules and shaded bands as cells of their own: -, a long dash run, :, ~. One such mark in either track makes the merge refuse, because the mark is not an amount and can sit in the same row as a real value. A ~ read from a rule in the header row also counts as a column label, and two labelled tracks never merge. The leftover track is then a headerless, mostly empty column, and the sparse-column check rejects the whole table. The page keeps its text, but the table is gone, with no warning.

Steps to reproduce

  1. Build a grid that the OCR table cleanup receives: a label column, two value columns, and a third value column split into two tracks 40 px apart. Put the values of the third column in the left track on most rows and in the right track on the others.
  2. In one row, put a value in the left track and a long dash run in the right track.
  3. Run the disjoint-column merge and then the OCR table post-processing on the grid.
  4. The merge leaves the two tracks apart, and the post-processing returns no table.

The unit tests split_amount_column_with_rule_marks_is_merged and table_with_a_split_amount_column_and_rule_marks_is_kept in crates/xberg/src/table_core.rs use invented labels and amounts for this grid.

Relevant files and configuration

  • crates/xberg/src/table_core.rs: the disjoint-column merge, its amount test, its header-label test and the merge of the cells.
  • crates/xberg/src/pdf/table_reconstruct.rs: the sparse-column check that drops the table.
  • Tesseract OCR route, any configuration that OCRs a scanned table.

How it was found

A real-world scanned document (not shareable) lost a table after #1936. That change made an inset scan with an unreadable text layer take the full-page scan route: Tesseract page segmentation mode 11 and a render at the raster's own density. On that route, the table's amount columns split into two tracks, and rule marks landed in the tracks.

This fix removes one of two causes. The table cleanup also keeps at most two header rows. When a scanned header band has three rows (the header text, then a row with a stray glyph or a section label), the cleanup moves the top row, which holds the real header text, into the data. A sparse column then loses its header label, and the sparse-column check can still drop the table. That limit is out of scope here, because it also decides the header of layout-guided tables (#1558).

Fix

When the merge compares the two tracks, a cell with no letter or digit counts as empty, and a header cell of that kind is not a column label. The header is every row above the first row that holds an amount, so a stray glyph under the header text is not taken for data. The merged cell keeps the real value and drops the mark; a lone mark stays where it is the only content. A data cell with a letter still blocks the merge, and two separately labelled columns still stay apart.