Skip to content

fix(pdf-to-docx): reconstruct tables instead of flattening them - #271

Merged
slaveofcode merged 1 commit into
developfrom
fix/pdf-to-docx-tables
Aug 17, 2026
Merged

fix(pdf-to-docx): reconstruct tables instead of flattening them#271
slaveofcode merged 1 commit into
developfrom
fix/pdf-to-docx-tables

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

The PDF→Word converter was dumping every table row as a paragraph (cells run together), which is what users saw. Now it detects tables and emits real Word tables.

How: cluster the positioned text into rows, split each row into cell segments on wide column gaps, and when ≥2 adjacent rows share aligned columns, build a table (docx Table/TableRow/TableCell). Headings and paragraphs are kept for everything else. Also fixed pdf.js's synthetic whitespace items bridging column gaps and merging cells.

Tests: reconstructBlocks/segmentsOf/clusterColumns unit tests + a full pdf-lib→pdf.js end-to-end regression test that draws a table and asserts it round-trips to a table (this is how the whitespace bug was caught).

Best-effort still applies (borderless/merged-cell/multi-column tables may need cleanup), and the UI note reflects that. Verify: 1358 tests green, lint 0 errors, build OK.

The converter flattened every table row into a paragraph. Now it detects
grid-like regions from the positioned text — rows that split into columns
that line up across ≥2 rows — and emits real Word tables, keeping headings
and paragraphs for the rest. Also fixes pdf.js synthetic whitespace items
merging adjacent cells. Pure reconstructBlocks (segmentsOf, clusterColumns)
unit-tested + a pdf-lib→pdf.js end-to-end regression test.
@slaveofcode
slaveofcode merged commit 4de0d65 into develop Aug 17, 2026
1 check passed
@slaveofcode
slaveofcode deleted the fix/pdf-to-docx-tables branch August 17, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant