Join pages from various documents into one in C#
1 min readOct 12, 2019
GroupDocs.Merger allows to merge or join 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);
merger.Save(filePathOut);
}
Learn more about the API features and announcements here.