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 stream;
  • Instantiate JoinOptions object and specify desired page numbers or page range to join;
  • Call Join method and pass joined document file path or stream 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, 4, RangeMode.OddPages);

using (Merger merger = new Merger(filePath, loadOptions))
    merger.Join(filePath2, joinOptions);

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 .NET library we provide simple, but powerful free Apps.
You are welcome to merge your documents with our free online GroupDocs Merger App.