Word documents with the docx4j tools
Filling a template (the flagship workflow)
describe_templateon the template. Readkindandhow_to_fill.- OpenDoPE / content-control templates (
data_format: "xml"): copyskeleton_xml, replace sample values with real data (duplicate or remove repeated elements; conditions are evaluated against the data), pass the whole XML document as thedatastring tofill_template. - Mail-merge templates (
data_format: "json"): passdataas a JSON object keyed bymerge_fields(case-insensitive). Fields inmerge_field_formatscarry date/number switches - give dates as 2026-09-01 and numbers as plain digits. - All formatting comes from the template; never rebuild a template by hand.
Authoring a new document
- Prefer
markdown_to_docx: headings, numbering, GFM tables, footnotes, task lists, TeX math ($..$) become native Word constructs. Passstyles_template_pathto inherit an organisation's styles. html_to_docxwhen the content is HTML (loose HTML fine; MathML becomes real equations; class names matching Word style names map to those styles).
Reading a document
docx_to_markdownpreserves structure (headings, tables, footnotes, equations as TeX).extract_textis plain text only.
Converting
convert_to_pdfrenders equations; checkfont_substitutionsin the result and tell the user if fonts were substituted.convert_to_htmlproduces a standalone page with native MathML.
Ground rules
- Every path must be inside the server's allowed roots (shown in its
instructions). Writers refuse to overwrite without
overwrite: true. - Results over the inline cap need an
output_path.