0

I am looking to use Docx4j, specifically to convert html pages to word documents, so I was playing around with it, but I am unable to get the sample code in the git repo to work.

XHTML URL to word doc specifically is what is causing me issues. When I run the code, I obtain a mass of errors when converting, such as

[http-bio-8080-exec-10] ERROR run.FontSize - TODO FontSize Handle units: 2 as well as other errors relating to getColWidth for col1, among other things. When it finally crashes, I get a nullPointerExeption

@ line 974 | traverse in org.docx4j.convert.in.xhtml.XHTMLImporterImpl

which is if (listHelper.peekListStack().getElement()!=null && listHelper.peekListStack().getElement().getAttribute("class")!=null)

Are there any configuration changes I need to make to get the XHTMLImporter working out of the box?

I am using it from this Maven Repo, and this seems to be the most up to date version.

Docx4j seems to be working fine by itself, as I have successfully created and written to a docx file, but this issue seems to be plugin-specific. Any ideas on what is happening?

Shrivar R
  • 123
  • 1
  • 12
  • What URL are you using in the sample code? The configured URL in the sample class doesn't validate as XHTML, so that could be the root cause of your issues. Try importing a simple (compliant) XHTML page, and go from there. – Ben Jul 01 '14 at 10:05

1 Answers1

0

For the NPE, please lodge a bug report at https://github.com/plutext/docx4j-ImportXHTML/issues?state=open including a simple test case so it can be reproduced.

To work around your font size issue, you'll need to use a supported font size unit. See https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/model/properties/run/FontSize.java

JasonPlutext
  • 15,352
  • 4
  • 44
  • 84