docx4j downloads
source code
We'd like to encourage you to use the docx4j source code in your IDE, so we put this option near the top.
This will greatly assist your LLM-assisted coding efforts, since it is the difference between recalling docx4j imperfectly and knowing it with certainty.
- Fork https://github.com/plutext/docx4j [optional but recommended]
- git clone your fork, or git clone https://github.com/plutext/docx4j
- mvn clean install -Dgpg.skip=true
- Import the Maven pom in your IDE. In Eclipse, that's File > Import > Maven > Existing Maven Projects.
Similarly, you can fork https://github.com/plutext/docx4j-ImportXHTML
Be sure to build once (with mvn install as above), so important XJC-generated code is present. Or point your agent at the -sources jars in ~/.m2, which IDEs download anyway.
maven pom
docx4j is in Maven Central: Select one and only one of:
docx4j-ImportXHTML (LGPL) is in Maven Central:
- docx4j-ImportXHTML-core 17.3.5 beside one of the above.
Its source and samples are at github.com/plutext/docx4j-ImportXHTML.
Take note if upgrading from Java 8 etc: docx4j v11.5 and later use Jakarta XML Binding API 4.0 (and v11.4 uses Jakarta XML Binding API 3.0), as opposed to JAXB 2.x used in earlier versions (which import javax.xml.bind.*). Since v11.4 and later use jakarta.xml.bind, rather than javax.xml.bind, if you have existing code which imports javax.xml.bind, you'll need to search/replace across your code base, replacing javax.xml.bind with jakarta.xml.bind. You'll also need to replace your JAXB jars (which Maven will do for you automatically; the bundle jars below already contain them).
bundle jars, without Maven (Java 11 and later)
We no longer build zip distributions. If you don't use Maven or Gradle (a plain classpath, say, or docx4j from Python with JPype), docx4j 17.3.6 comes as two self-contained jars in Maven Central:
- docx4j-bundle-17.3.6.jar (35 MB): docx4j with the JAXB reference implementation, digital signatures, Markdown import and export, and docx differencing. On its own, it is everything but PDF output.
- docx4j-bundle-extras-17.3.6.jar (15 MB): PDF output (docx4j-export-fo, with the docx4j FO renderer, the chart renderer and fonts). Put it beside docx4j-bundle of the same version; it does not work alone. It carries its own copy of org.apache.fop, so don't put Apache FOP's jars beside it.
- docx4j-ImportXHTML-bundle-17.3.5.jar (4.5 MB): docx4j-ImportXHTML, with openhtmltopdf, PDFBox, apache-mime4j (for MHT input) and jsoup. Put it beside docx4j-bundle of the same version; it does not work alone. It shares no classes with docx4j-bundle-extras, so all three can go on one classpath. Like docx4j-ImportXHTML-core, it is LGPL v2.1.
None of these declare any dependencies: what needs is inside. To see docx4j's logs, add a logging implementation (see Logging, below).
MOXy: the bundle uses the JAXB reference implementation, and there is no MOXy bundle. To use MOXy, depend on docx4j-JAXB-MOXy with Maven or Gradle, as above. If you need the jars themselves, make a pom that declares only docx4j-JAXB-MOXy and run mvn dependency:copy-dependencies: docx4j and everything it needs land in target/dependency.
Docs - Getting Started?
Docx4j_GettingStarted is in the docs folder on GitHub, as PDF, HTML, Markdown and docx.
Cheat sheet
Docx4j Code Generation
Download/install the Docx4j Helper AddIn for Microsoft Word to generate docx4j Java code from within Word, see the XML, plus more.
Or use the webapp (which also helps with pptx and xlsx).
Sample code
Sample code is not in Maven Central, and there are no longer zip files of it. The samples are in the docx4j repository; for docx4j 17.3.6:
- docx4j: docx4j-samples-docx4j
- docx4j-ImportXHTML: docx4j-ImportXHTML-samples (there is also org.pptx4j.samples)
- pptx4j: docx4j-samples-pptx4j
- xlsx4j: docx4j-samples-xlsx4j
Beside them in the repository are samples for PDF output, digital signatures, docx differencing, SmartArt and more. To build and run them, clone the repository (see source code, above).
Docx4j properties
Sample properties file may be found at docx4j-samples-resources/src/main/resources/docx4j.properties
Logging
To see docx4j logs, you'll need a concrete logging implementation. docx4j logs through SLF4J; the bundle jars contain the SLF4J API but no implementation, so add one (logback, or log4j2 with its SLF4J binding, for example). Config files for log4j2 and logback may be found in the sample resources