plutext / docx4j-ImportXHTML

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

text-indent support #58

Open gangz opened 5 years ago

gangz commented 5 years ago

I encountered a HTML file which contains text-indent style like following:

<p style="margin-left:2em;text-indent:-2em;">text</p>

Currently docx4j-ImportXHTML still does not support it yet.

gangz commented 5 years ago

I written a test to reproduce the issue like following:

@Test public void testHangingIndent() throws Docx4JException, JAXBException {
    String xhtml= "<p style=\"margin-left:2em;"
            + "text-indent:-2em;\">"
            + "text</p>";
    wordMLPackage.getMainDocumentPart().getContent().addAll(
            convert(xhtml));
    List<Object> matches = wordMLPackage.getMainDocumentPart().getJAXBNodesViaXPath("//w:pPr", false);
    PPr ppr = (PPr) matches.get(0);
    assertEquals(ppr.getInd().getLeft().intValue(),480);
    assertEquals(ppr.getInd().getHanging().intValue(),480);
}
gangz commented 5 years ago

I tried to fix the problem, and finally it was fixed in

But I do not sure whether the modification fits on the design principle of docx4j , so I have not create a PR, just add comments here for information purpose.

Thanks for the great work of docx4j

plutext commented 3 years ago

Thanks for this. You are correct; text-indent is not supports (but margin-left is). So hanging indents don't work.