plutext / docx4j-ImportXHTML

Converts XHTML to OpenXML WordML (docx) using docx4j
136 stars 125 forks source link

Table width is not displayed correctly in LibreOffice #98

Closed florinco closed 8 months ago

florinco commented 11 months ago

Given I want to convert following XHTML (containing a table tag with style width 100%) to DOCX

xhtml = "<html>"
        + "<head>"
        // + "<style>@page {size: A4 portrait; margin-left: 2cm; margin-right: 2cm;}</style>"
        + "</head>"
        + "<table style=\"width:100%;\"><tbody><tr><td>test</td><td>test</td></tr></tbody></table>"
        + "</html>";

When I open the resulting .docx in LibreOffice the table expands over the page width. The resulting .docx is displayed correctly in MS Word as this is probably recalculating the columns width before displaying.

I'm running the test via org.docx4j.samples.XhtmlToDocxAndBack

I am happy for any provided hint :).

florinco commented 8 months ago

I solved the issue by passing the correct parameters in renderer

XHTMLImporter.setRenderer(new DocxRenderer(20f, 20));