bug: PDF: grouped table headings lose their column spans
Description
On page 85 of this public PDF, the three grouped headings are retained, but their column spans are lost. Each heading covers a description/amount pair in the source table.
The structured table has six columns, but its header cells are:
| Heading | Actual col / colSpan |
Expected col / colSpan |
|---|---|---|
| Attività non commerciali | 0 / 1 | 0 / 2 |
| Attività commerciali | 1 / 1 | 2 / 2 |
| Attività neutre | 2 / 1 | 4 / 2 |
Column indices above are zero-based. The second and third headings are consequently associated with the wrong body columns. tables[].cells also has a three-cell header row above six-cell body rows, and tables[].markdown emits three header/separator columns followed by six body columns.
The structured grid should preserve the two-column spans. If Markdown output flattens those spans, it should still keep a consistent six-column layout and the headings over their correct column pairs.
This follows #1803 / #1807. Our earlier patch restored the heading text but did not preserve these relationships; its integration test explicitly accepted three header cells above six body cells. The original submitted PR revision and 1.3.0 produce identical table cells for this page, so this is an incomplete part of that fix, not a later regression. The separate word-spacing defect is covered by #1948.
Steps to reproduce
Download the PDF above as circular-1-2026.pdf.
Install @xberg-io/[email protected] in a scratch directory and save this as repro.mjs:
npm install @xberg-io/[email protected]import { readFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';
import { extract, ExtractInputKind } from '@xberg-io/xberg';
const [filename, pageArg, expectedHash] = process.argv.slice(2);
const page = Number(pageArg);
const bytes = await readFile(filename);
if (createHash('sha256').update(bytes).digest('hex') !== expectedHash) {
throw new Error('PDF SHA-256 mismatch');
}
const output = await extract(
{ kind: ExtractInputKind.Bytes, bytes, filename, mimeType: 'application/pdf' },
{
disableOcr: true,
useCache: false,
enableQualityProcessing: false,
outputFormat: 'plain',
pages: { extractPages: true },
includeDocumentStructure: true,
pdfOptions: { extractTables: true, ocrInlineImages: false },
},
);
const result = output.results[0];
console.log(JSON.stringify({
pageText: result.pages[page - 1].content,
tables: result.tables.filter(t => t.pageNumber === page),
nodes: result.document.nodes.filter(n => n.page === page),
}, null, 2));Run:
node repro.mjs circular-1-2026.pdf 85 75436a448f828d68fc076310373b3753f189a32d51de73c4ffe1092597eb3f84 > result.jsonFind the table node in nodes and inspect content.grid.cells with row: 0, alongside the six-column body. Compare tables[0].cells and tables[0].markdown. The script verifies the original PDF hash before extraction.
Relevant files and configuration
Reproduced with the published macOS arm64 Node binding, @xberg-io/[email protected]. OCR, caching and quality processing are disabled; table extraction and document structure are enabled. No application-side transformation is involved.
Source: xberg-io/xberg