Question: I am trying to automate docx report generation process. For this I am using java and docx4j. I have a template document containing only single page.I would like to copy that page modify it and save it in another docx document.The output report is of multiple similar pages with modification from the template. How do I go about it.

PS : java and docx4j are my first choice but I am open to solutions apart from java and docx4j.

Answer: 
Leaving it up to you to modify the template, here is how you could add one document to the end of another document. Suppose `base.docx` contains "This is the base document." and `template.docx` contains "The time is:", then after executing this code:

```
WordprocessingMLPackage doc = Docx4J.load(new File("base.docx"));
WordprocessingMLPackage template = Docx4J.load(new File("template.docx"));
MainDocumentPart main = doc.getMainDocumentPart();

Br pageBreak = Context.getWmlObjectFactory().createBr();
pageBreak.setType(STBrType.PAGE);
main.addObject(pageBreak);

for (Object obj : template.getMainDocumentPart().getContent()) {
    main.addObject(obj);
}
main.addParagraphOfText(LocalDateTime.now().toString());

doc.save(new File("result.docx"));

```

Then `result.docx` will contain something like:

```none
This is the base document.

^L

The time is:
2018-04-16T17:37:13.541984200

```

(Where ^L represents a page break.)
> 
> To be more precise my original template is containing only header and some styling component. 
> 
> 
> 

This kind of information can be stored in a Word stylesheet (.dotx file).

> 
> PS : java and docx4j are my first choice but I am open to solutions apart from java and docx4j. 
> 
> 
> 

A good tool would be [pxDoc](https://www.pxdoc.fr): you can specify a dedicated stylesheet in your document generator, or use "variable styles"and specify the stylesheet only when you launch the document generation