Skip to content

fix(table rendering): correct incorrect table width percentage calcul…#726

Merged
kevinleturc merged 1 commit into
opensagres:masterfrom
rowstop:master
Mar 23, 2026
Merged

fix(table rendering): correct incorrect table width percentage calcul…#726
kevinleturc merged 1 commit into
opensagres:masterfrom
rowstop:master

Conversation

@rowstop
Copy link
Copy Markdown
Contributor

@rowstop rowstop commented Mar 20, 2026

Summary

This PR fixes DOCX-to-PDF table rendering issues in XWPF2PDFViaITextConverter, especially for tables that use vertical merges (vMerge), and aligns percentage width handling with OOXML semantics.

Changes and Reasons

1) Fix off-by-one in colspan coverage check (core layout fix)

File

  • /xdocreport/thirdparties-extension/fr.opensagres.xdocreport.itext.extension/src/main/java/fr/opensagres/xdocreport/itext/extension/ExtendedPdfPTable.java

Change

  • In getCellAboveWithColspan(...), changed:
    • cell.getColspan() + colCursor >= indexFrom
    • to
    • cell.getColspan() + colCursor > indexFrom

Why

  • The previous condition was an off-by-one boundary error.
  • It could incorrectly treat a left-adjacent non-spanning cell as covering the current column.
  • That caused wrong skip behavior in rowspan/colspan navigation and led to downstream cell misalignment in PDF output (content appearing in wrong columns).

2) Correct percentage table width conversion in core table utilities

Files

  • /xdocreport/thirdparties-extension/fr.opensagres.poi.xwpf.converter.core/src/main/java/fr/opensagres/poi/xwpf/converter/core/utils/XWPFTableUtil.java
  • /xdocreport/thirdparties-extension/fr.opensagres.poi.xwpf.converter.core/src/main/java/fr/opensagres/poi/xwpf/converter/core/styles/table/cell/TableCellWidthValueProvider.java

Change

  • For w:type="pct" widths, changed conversion:
    • /100f -> /50f

Why

  • In OOXML, percentage widths are stored in fiftieths of a percent.
  • Example: 5000 means 100%.
  • Dividing by 100 underestimates percentage width by half; dividing by 50 is the correct conversion.

Validation

  • Reproduced the issue using the provided DOCX templates and XWPF2PDFViaITextConverter.
  • Confirmed that table structure with vMerge is now stable after the colspan boundary fix.
  • Confirmed percentage width behavior is consistent with OOXML semantics after conversion fix.
  • Temporary debug instrumentation used during investigation was removed before finalizing changes.

Scope

  • No functional API changes.
  • No behavior changes outside table layout calculation/rendering.
  • Final patch keeps only necessary production fixes (debug-only edits excluded).

@rowstop
Copy link
Copy Markdown
Contributor Author

rowstop commented Mar 20, 2026

#725

@angelozerr
Copy link
Copy Markdown
Member

Thanks @rowstop for yoru contribution.

@kevinleturc is there any chance that you review the PR please?

@kevinleturc kevinleturc merged commit 4bf1ef5 into opensagres:master Mar 23, 2026
3 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.

3 participants