Repository navigation
Description
Context
Found while checking the document-reading chain end to end (seshat v1.2.63/v1.2.64, SeshatOS backend, real models). Both cases below come from a real invoice (invoice2.pdf, a Saeco invoice in Dutch), read with the pure-Go PDF reader (internal/pdftext). The content of the page is complete and correct; these are quality issues, not data loss. Neither is urgent. This issue records that they are real so they can be picked up if they hurt in practice.
1. Reading order follows drawing order
pdftext builds lines in the order the producer drew them (buildLines in internal/pdftext/layout.go). That is on purpose: it keeps the reading order of columns in papers and books without a model. But when a producer draws a block out of order, the markdown comes out in that order. On the invoice, the items table was drawn first, so it appears before "Kopie factuur", the addresses and the invoice header, although it sits in the middle of the page.
A plain "sort blocks by top" rule is not enough and would break columns:
- two-column papers must stay in column order;
- the invoice itself has two blocks side by side (billing address, delivery address), so a prudent rule that leaves side-by-side blocks alone would not reorder it either.
What it needs is a real reading-order analysis (XY-cut or a layout-model based ordering, as Docling does), validated on the corpus used for the table work (papers, a 60-page French book, letters, CVs) so that columns do not regress.
2. A header that spans two columns is repeated in each
In a header row, a chunk that crosses a column separator is written in each column it covers (that is the standard behaviour for a spanning heading such as "Results 2020" over Q1 and Q2). On the invoice, "BTW Hoeveelheid" is really two headings, "BTW" over "21 %" and "Hoeveelheid" over "1 PCS", set 3 pt apart, so the table header reads | BTW Hoeveelheid | BTW Hoeveelheid |. Nothing is lost, the text is only duplicated.
splitChunk in internal/pdftext/tablebuild.go only splits where the gap between two words is at least splitGapEm (0.6 em). Lowering that gap splits real spanning headings by mistake. A fix has to tell the two cases apart, for example from the body: each word sits over its own column of body text and no word is centred over the whole span.
How to reproduce
Any PDF whose producer draws a table before the text above it, and whose header titles are set closely (an invoice from an ERP or web shop). The Saeco invoice used here is invoice2.pdf (not committed).
Activity