Merge pages from various documents

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Merger MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-merger -- dnx GroupDocs.Merger.Mcp --yes
Folders, licensing and more →

With GroupDocs.Merger you can combine different pages from multiple source documents into a single document.

  • To merge the entire first document along with specific pages from the second and subsequent documents, you can make use of the PageJoinOptions object, which is explained on this page.
  • To merge arbitrary pages from all the source documents, you can use the PageBuilder object, which is explained in detail in the Merge pages in the arbitrary order section.

Using the PageJoinOptions object, you can merge the source document with specific document pages from the joined documents 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:

  • Create a Merger object and provide the path or stream of the source file.
  • Create a PageJoinOptions object and specify desired page numbers or page ranges to join.
  • Use the Join to add another source document. Provide the path or stream of the source file and the PageJoinOptions object as parameters. Repeat this step for every joined document part.
  • Save the resulting document by calling the Save method and providing a file path.

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";

PageJoinOptions joinOptions = new PageJoinOptions(1, 4, RangeMode.OddPages);

using (Merger merger = new Merger(filePath))
{
    merger.Join(filePath2, joinOptions);
    merger.Save(filePathOut);
}