talira

JAXB-based Java library for Word docx, Powerpoint pptx, and Excel xlsx files

open coreApache-2.0self-hostablefree

docx4j is a Java library for creating, editing and saving Office Open XML packages (docx, pptx, xlsx), with the XML mapped to Java objects through JAXB. For document generation it supports variable replacement, MERGEFIELDs and content-control data binding to custom XML, with the OpenDoPE extensions for repeats, conditions and components, so a .docx template can be filled from XML data. It exports HTML and PDF (through XSL-FO and Apache FOP, or by driving Word through documents4j or Microsoft Graph), creates charts and anonymises documents. Plutext created it and sponsors it; the library is Apache-2.0, and Plutext sells a Docx4j Enterprise Edition with document merging and support.

Problems it solves

  • fill Word content controls from an XML document in a Java service, including repeating table rows
  • generate .docx contracts on the JVM where conditions and repeats are marked up in the template itself
  • read, change and save Word, PowerPoint and Excel files from Java as typed objects instead of raw XML
  • convert generated .docx files to PDF from Java without Word installed
  • produce tagged PDF or PDF/A from Word documents in a Java backend
  • an Apache-licensed Java alternative to paid Word libraries for document automation
  • strip personal data out of a .docx before sharing it, from Java
  • create charts inside Word or PowerPoint files from a Java program
  • replace MERGEFIELDs in an existing Word template with values from Java

Features

  • open, create and edit docx, pptx and xlsx packages as JAXB objects
  • document generation by variable replacement, MERGEFIELD or content-control data binding
  • OpenDoPE custom XML binding with repeats, conditionals, pictures, rich text and checkboxes
  • import XHTML into Word documents
  • export to HTML and to PDF via XSL-FO and Apache FOP (tagged PDF, PDF/A, PDF/UA)
  • PDF through Word via documents4j or Microsoft Graph for Word-level fidelity
  • create and edit charts in docx, pptx and xlsx
  • anonymise or sanitise documents
  • font substitution and embedded fonts
  • Python package (docx4j on PyPI) with no JVM

Limitations

  • Doesn't read legacy binary Office files such as .doc and .xls: it works with docx, pptx and xlsx1
  • Doesn't render PDFs exactly as Word does with its own converter: for Word-identical output it drives Word through documents4j or Microsoft Graph1

Alternatives

The same job

These do what docx4j does.

  1. rdocx Native DOCX creation, editing, comparison, layout, and rendering
  2. Carbone Generates PDF, DOCX and other documents from JSON data and Office templates
  3. Docmosis API-first, template-based document generation
  4. Sablon Ruby document template processor based on docx templates and Mail Merge fields
  5. Aspose.Words Create, edit, render and convert Word documents to multiple formats without using external software
  6. docxtemplater Powerful Word, PowerPoint and Excel generation

Compare docx4j with the top 3