fix(table rendering): fix table cell background color and column width with percentage#733
Open
codefan wants to merge 1 commit into
Open
fix(table rendering): fix table cell background color and column width with percentage#733codefan wants to merge 1 commit into
codefan wants to merge 1 commit into
Conversation
…h with percentage
1. Fix table cell shading background color not rendered when w:fill='auto'
- In ColorHelper.getFillColor(), when w:fill='auto' and w:val='solid',
fall back to w:color attribute for the actual fill color per OOXML spec.
- This fixes dark blue header backgrounds that were lost during conversion.
2. Fix incorrect table column widths when cells use percentage-based widths
- In XWPFTableUtil.computeColWidths(), when cells define w:type='pct'
widths, use those proportions instead of grid column twips values.
- Grid column widths are always in absolute twips and may not reflect
the intended percentage-based layout, causing some columns to be
too narrow or too wide.
- Scale cell percentage proportions to match grid total width to
preserve correct overall table width.
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
Two fixes for table rendering in DOCX to PDF conversion:
1. Fix table cell shading background color not rendered when
w:fill="auto"Problem: Table header cells with dark blue background (
#1A237E) and white text lose their background color during conversion, making white text invisible on the white page.Root cause:
ColorHelper.getFillColor()only reads thew:fillattribute from<w:shd>. When the DOCX uses<w:shd w:val="solid" w:color="1A237E" w:fill="auto"/>, thew:fill="auto"is resolved as white, while the actual color1A237Eis in thew:colorattribute.Fix: When
w:fill="auto", fall back to thew:colorattribute for the actual fill color, per the OOXML specification.2. Fix incorrect table column widths when cells use percentage-based widths
Problem: Table columns have incorrect proportions — some columns are too narrow, causing text to be clipped.
Root cause:
XWPFTableUtil.computeColWidths()always uses absolute twips values from<w:gridCol>for column widths. When cells define percentage widths (<w:tcW w:type="pct">), the grid column twips may not reflect the intended proportions. For example, a grid column of 119 twips (~6pt) vs. a cell percentage of 18.24%.Fix: Added
computeColWidthsFromCells()that detects when cells use percentage widths and uses those proportions instead. The percentage values are scaled to match the grid total width to preserve correct overall table dimensions.Test
TableHeaderColorTestCasewith a Chinese DOCX document containing tables with colored headers.🤖 Generated with Claude Code