Merge pages from various documents

GroupDocs.Merger allows to merge the source document with specific document pages from joined document into one resultant document by specifying desired page numbers or page ranges. Joined documents should be of the same format.

 Here are the steps to join several document parts:

  • Instantiate Merger object with source document path or InputStream;
  • Instantiate JoinOptions object and specify desired page numbers or page range to join;
  • Call join method and pass joined document file path or InputStream to it specifying JoinOptions object as parameter. Repeat this step for every joined document part.
  • Call save method specifying file path to save resultant document.

The following code sample demonstrates how to join document parts:

String filePath = "c:\sample.docx";
String filePath2 = "c:\sample2.docx";
String filePathOut = "c:\output\result.docx";

JoinOptions joinOptions = new JoinOptions(1, 2);

Merger merger = new Merger(filePath);
merger.join(filePath2 , joinOptions);
merger.save(filePathOut);

More resources

Advanced Usage Topics 

To learn more about document merging features, please refer the advanced usage section.

GitHub Examples 

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App 

Along with full featured Java library we provide simple, but powerful free Apps. You are welcome to merge your documents with our free online GroupDocs Merger App.