Merging different word documets with below piece of code
public byte[] mergeWordDocs(List<byte[]> wordDocs, String appName) throws DocxGenerationException {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
Document output = new Document();
output.removeAllChildren();
for (byte[] wordFile : wordDocs) {
Document input = new Document(new ByteArrayInputStream(wordFile));
input.getFirstSection().getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
input.getFirstSection().getHeadersFooters().linkToPrevious(false);
input.getFirstSection().getPageSetup().setRestartPageNumbering(true);
output.appendDocument(input, ImportFormatMode.KEEP_SOURCE_FORMATTING);
}
output.save(os, SaveFormat.DOCX);
return os.toByteArray();
} catch (Exception ex) {
throw new DocxGenerationException("Exception occurred while merging word docs", ex);
}
}
getting below issue::
Expected Footer
Attached 2 images, where in footer value “LTM” got messed and came to mid in place of extreme right
i have to preserve page numbers based on source and header, footer same as like source doc with merge.