Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active June 8, 2023 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/f4d5b2e63fa8f34da102b8c84ce341f4 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/f4d5b2e63fa8f34da102b8c84ce341f4 to your computer and use it in GitHub Desktop.
Merge Word Documents with Java
// Merge Selective Pages of Word Documents using Java
Merger merger = new Merger("source_document.docx"))
{
// Set the merging options
JoinOptions joinOptions = new JoinOptions(2,3); // Specify the starting and ending page number
// Merge the documents
merger.join("document_to_merge.docx", joinOptions); // using joining settings
merger.join("another_document_to_merge.docx", new JoinOptions(new int[] { 2, 4, 6 })); // Specifying page number(s)
merger.save("output_document.docx"); // Saving merged document
}
// Merge Two Word Documents using Java
Merger merger = new Merger("source_document.docx"); // Load the source document
merger.join("document_to_merge.docx"); // Merge the document
merger.join("another_document_to_merge.docx"); // Merge additional documents
merger.save("output_document.docx"); // Save the merged document as output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment