Skip to content

verronpro/office-stamper

Repository files navigation

Office-stamper

Build Status Build Status Build Status Build Status

Introduction

Office-stamper (formerly docx-stamper) is a Java template engine that allows for dynamic creation of DOCX documents at runtime. You design a template using your preferred Word processor; and office-stamper will generate documents based on that template.

Key Features

  • Expression-based templating: Use Spring Expression Language (SpEL) for powerful template expressions

  • Comment-based processing: Add special instructions as comments in your Word documents

  • Formatting preservation: All formatting from the original template is preserved

  • Custom functions: Extend the templating capabilities with your own functions

  • Type-safe: Strong typing for Java integration

  • Flexible configuration: Customize the behavior to suit your needs

Quick Start

class Example {
    public static void main(String[] args) {
        // an object to use as context for the expressions found in the template.
        var context = new YourPojoContext(_, _ , _);

        var stamper = OfficeStampers.docxStamper();

        var templatePath = Paths.get("your/docx/template/file.docx");
        var outputPath = Paths.get("your/desired/output/path.docx");
        try(
            var template = Files.newInputStream(templatePath);
            var output = Files.newOutputStream(outputPath);
        ) {
            stamper.stamp(template, context, output);
        }
    }
}

Maven Coordinates

<dependency>
    <groupId>pro.verron.office-stamper</groupId>
    <artifactId>engine</artifactId>
    <version>2.8.0</version>
</dependency>

<!-- You also need to provide a dependency to Docx4J -->
<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-core</artifactId>
    <version>11.5.3</version>
</dependency>
<dependency>
    <groupId>org.docx4j</groupId>
    <artifactId>docx4j-JAXB-ReferenceImpl</artifactId>
    <version>11.5.3</version>
</dependency>

Latest Release

The latest release is v2.8.0. See the Release Notes for details.

Sample Code

The source code contains a set of tests showing how to use the features. If you want to run them yourself, clone the repository and run mvn test with the system property -DkeepOutputFile=true so that the resulting .docx documents will not be cleaned up and let you view them.

If you want to have a look at the .docx templates used in the tests, have a look at the sources subfolder in the test folder.

Contributing

Contributions are welcome! See the Contributing Guide for details on how to contribute to Office-stamper.

License

Office-stamper is released under the MIT License.

About

Easy-to-use template engine for creating docx documents in Java.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 20