How to convert HTML to .docx using docx4j?

I read several articles about converting htmlto .docx, and I found out that it docx4jgives pretty decent results. I wonder if anyone can provide me with the following information:

  • Necessary jarsand version.
  • Sample code to convert from htmlto .docx.

Sorry, I could not publish everything that I tried, because I have not tried anything in this task yet, although I use Apache POIfor the conversion bytes[]that I get from datatabseto htmlto output in rich text editorthe application jsf. Please enlighten me, I am lost in stress and confusion ...!

+4
source share
1 answer

To import XHTML, use

<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-ImportXHTML</artifactId>
    <version>3.0.0</version>
</dependency>

See further http://www.docx4java.org/blog/2013/11/docx4j-3-0-and-maven/

Sample code see https://github.com/plutext/docx4j-ImportXHTML/tree/master/src/samples/java/org/docx4j/samples

Please note that your input must be well-formed XML, so if you have HTML, you need to tidy it up first (with one of the many java libraries that can do this for you).

+4
source

All Articles