Auto-tagging: tables found by border detection never emit `TH`, while cluster-detected tables mark their first row as header
AutoTaggingProcessor.addTableRow already does the right thing for header cells —
cell.isHeaderCell() ? TH : TD, plus a Scope of Column/Row/Both — and the
comment above it says "First row uses TH + Scope="Column" for header identification".
But for tables that come from border detection, isHeaderCell() can never be true, so
the output is all TD with no Scope, and the JSON has no "is header" on any cell.
Reproduction (2.5.8, java -jar opendataloader-pdf-cli.jar in.pdf --format tagged-pdf,json):
- A synthetic 3×4 table with drawn cell borders, text header row over numeric columns:
/Table1,/TR4,/TD12,/TH0. Making the header row bold, or bold and grey-shaded, changes nothing. - docling's test page
2305.03393v1-pg9.pdf(a normal ruled table in a paper):/TR6,/TD41,/TH0; JSON"is header"never appears.
Why. TableBorderCell.isHeaderCell() is semanticType == SemanticType.TABLE_HEADER
(veraPDF-wcag-algs 1.31.44, TableBorderCell.java:118). The two ways a cell gets that
type:
- Inside veraPDF-wcag-algs — every
isHeaderCellpredicate there (TableBorderConsumer.java,TableChecker.java,ClusterTableConsumer.java) begins withif (cellNode.getInitialSemanticType() != SemanticType.TABLE_HEADER) return false;. They propagate aTHthat the input structure tree already carries; they are validator logic and never infer a header from the page. On an untagged PDF the initial type is neverTABLE_HEADER, so this path is closed. - Inside opendataloader —
ClusterTableProcessor.setTableCellsSemanticTypesassignsrowNumber == 0 ? TABLE_HEADER : TABLE_CELLto every cell of a cluster-detected table.TableBorderProcessor/AbstractTableProcessortake their tables fromStaticContainers.getTableBordersCollection()and never set a semantic type on the cells, so they staynull.
So the "first row is the header" rule exists, but only on the cluster path. Tables with
ruled borders — the common case in reports and papers — get no header at all, and the
comment in AutoTaggingProcessor describes the cluster path only.
Why it matters. A screen reader announces column headers from TH/Scope; with all
TD the user hears bare numbers. This is also invisible to conformance checks: the
same output passes 97 of 106 PDF/UA-1 rules in veraPDF, because no validator can know
that a TD should have been a TH. It is the kind of gap only a correctness check
sees.
Proposed fix. Apply the same rule on the border path — in AbstractTableProcessor
after getTables, or in TableBorderProcessor, call the equivalent of
setTableCellsSemanticTypes so row 0 → TABLE_HEADER. That makes both paths
consistent, makes the existing AutoTaggingProcessor comment true, and lights up the
Scope and JSON "is header" code that is already there. Two refinements worth
discussing, but separable: (a) also mark column 0 as a row header when it is
non-numeric and the rest of the row is numeric — Scope=Row is already handled; (b)
prefer a bold or shaded first row as the header signal when present, and fall back to
row 0 otherwise.
Happy to open the PR for the base change (row 0 on the border path, plus a
TableBorderProcessorTest case) if that rule is acceptable; I would rather confirm it
than guess which of the three you want.
Source: opendataloader-project/opendataloader-pdf