fix(pdf-to-docx): reconstruct tables instead of flattening them - #271
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 (
docxTable/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/clusterColumnsunit 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.