For the complete documentation index, see llms.txt. This page is also available as Markdown.

Advanced Features

Advanced Word document features including watermarks, protection, table of contents, section breaks, and document properties

Advanced capabilities for production-grade Word documents.


Watermarks

Add semi-transparent text watermarks like "DRAFT", "CONFIDENTIAL", or custom text to every page:

word()
    .addHeading( "Confidential Report", 1 )
    .addParagraph( "Sensitive financial data." )
    .addWatermark( "CONFIDENTIAL" )
    .save( "confidential-report.docx" )

The watermark is rendered as large, light gray, centered text in the document header, appearing on every page.

Multiple watermarks can be added with different text:

word()
    .addWatermark( "DRAFT" )
    .addParagraph( "Work in progress..." )
    .save( "draft.docx" )

Document Protection

Password-protect your document so users must enter a password to view it:


Table of Contents

Insert a Table of Contents field that Word auto-generates when the document is opened:

The TOC field captures headings 1–3 by default. When opened in Word, the user will be prompted to update the table of contents to populate the entries and page numbers.


Section Breaks

Use section breaks to apply different page setups within the same document:


Page Setup

Margins

Set all four margins in centimeters:

Page Size

Orientation

Headers & Footers


Document Properties

Set metadata that appears in Word's document properties panel:

These properties are visible in Word via File → Info → Properties and are included in the YAML front matter when exporting to Markdown via toMarkdown().


Default Font

Apply a consistent font family and size to all existing text runs:


Fluent Helpers

tap() — Side Effects

Execute an action mid-chain without breaking the flow:

when() — Conditional Branching

Conditionally execute a block in the fluent chain:


Document Cleanup

WordDocument implements AutoCloseable. Release POI resources when done:

Or use try-with-resources in Java interop scenarios.


User GuideFormattingExamplesFluent API

Last updated

Was this helpful?