Skip to content

PDF to Word: keep a ruled table whose text runs past a cell - #986

Merged
KnifeLemon merged 1 commit into
mainfrom
fix/pdf-table-overflow
Nov 1, 2026
Merged

KnifeLemon merged 1 commit into
mainfrom
fix/pdf-table-overflow

Conversation

@KnifeLemon

Copy link
Copy Markdown
Owner

Refs #138. The sample from @cache51 there (input_p2.pdf, a garment measurement sheet printed from a spreadsheet) has every cell ruled, yet PDF → DOCX gave no table: 63 loose paragraphs.

Cause

The grid was found (40 rows × 17 columns), then thrown away because of one word. "Front NK Drop (from HPS to Edge)@ COLLAR NOTCH" is longer than its column:

  • the spreadsheet cut it off at the cell, and the PDF only clips the rest;
  • the text reader still sees the whole word "NOTCH", which then sits across the cell's right rule;
  • the table finder takes any rule through a word as a sign of a chart or a strike-through, so the whole table became text.

Change

PdfDocumentReader.Tables:

  • A word that runs on past a vertical rule stays in the cell it starts in.
  • It's allowed for up to one in twenty of the grid's words (at least one), so a chart with labels across its lines still stays text.
  • A horizontal rule through a word (a strike-through) still means no table.

Result on the sample

Before After
Word tables 0 1 (40 rows)
"…@ COLLAR NOTCH" a loose paragraph in its cell, next to 1/8 and 3 1/2

Merged cells, shading and the heavy frame come through too. Still different from the PDF, not part of this fix:

  • rows come out a little taller, so the table runs onto a second page;
  • the item labels come out bold;
  • the jacket sketch lands under the table instead of beside it.

Test

PdfTableTests.Long_text_running_past_its_cell_stays_in_that_cell draws a 4 × 3 grid in code, with one label whose last word straddles its cell's right rule. It checks that the label, its tolerance and its value each land in their own cell. The 27 existing PDF table tests still pass, including Boxes, underlines and empty grids stay text.

🤖 Generated with Claude Code

A spreadsheet printed to PDF cuts long text off at its cell, and the PDF
only clips the rest, so the hidden part still reads as part of the word.
That word then sat across the cell's right rule, and the table finder
took any rule through a word as a sign of a chart, dropping the whole
40-row measurement table from #138 to plain text.

A word that runs on past a vertical rule now stays in the cell it starts
in, for up to one in twenty words of the grid (at least one). A rule
through a word's height (a strike-through) still means no table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KnifeLemon
KnifeLemon merged commit 328225c into main Nov 1, 2026
10 checks passed
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