All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.java.pro.verron.officestamper.preset.OfficeStampers Maven / Gradle / Ivy

Go to download

Office-stamper is a Java template engine for docx documents, forked from org.wickedsource.docx-stamper

There is a newer version: 2.6.0
Show newest version
package pro.verron.officestamper.preset;

import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import pro.verron.officestamper.api.OfficeStamperConfiguration;
import pro.verron.officestamper.api.OfficeStamperException;
import pro.verron.officestamper.api.StreamStamper;
import pro.verron.officestamper.core.DocxStamper;

import java.io.InputStream;

/**
 * Main class of the docx-stamper library.
 * 

* This class can be used to create "stampers" that will open .docx templates * to create a .docx document filled with custom data at runtime. * * @author Joseph Verron * @version ${version} * @since 1.6.4 */ public class OfficeStampers { private OfficeStampers() { throw new OfficeStamperException("OfficeStampers cannot be instantiated"); } /** * Creates a new DocxStamper with the default configuration. * Also adds the {@link Preprocessors#removeLanguageProof()} and {@link Preprocessors#mergeSimilarRuns()} * preprocessors. * * @return a new DocxStamper */ public static StreamStamper docxStamper() { return docxStamper(OfficeStamperConfigurations.standardWithPreprocessing()); } /** * Creates a new instance of the {@link DocxStamper} class with the specified {@link OfficeStamperConfiguration}. * * @param config the configuration for the docx stamper * * @return a new instance of the {@link DocxStamper} class */ public static StreamStamper docxStamper( OfficeStamperConfiguration config ) { return new StreamStamper<>( OfficeStampers::loadWord, new DocxStamper(config) ); } private static WordprocessingMLPackage loadWord(InputStream is) { try { return WordprocessingMLPackage.load(is); } catch (Docx4JException e) { throw new OfficeStamperException(e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy