ImageGear .NET - Updated May 1, 2018
Merge Multiple PDFs
User Guide > How to Work with... > PDF > How to... > Merge Multiple PDFs

The following example illustrates how to merge two multi-page PDF documents into one document:

C#
Copy Code
using ImageGear.Formats.PDF;
       // Merges two PDF document into a third PDF document.
       ImGearPDFDocument MergePdfDocuments(ImGearPDFDocument igFirstDocument, ImGearPDFDocument igSecondDocument)
       {
           // ImageGear uses zero-based numeration of pages in document.
           int FIRST_PAGE_INDEX = 0;

           // Create new PDF document for result.
           ImGearPDFDocument igResultDocument = new ImGearPDFDocument();

           // Copy all pages of first document into result document.
           for (int pageIndex = FIRST_PAGE_INDEX; pageIndex < igFirstDocument.Pages.Count; pageIndex++)
               igResultDocument.Pages.Add(igFirstDocument.Pages[pageIndex].Clone());

           // Copy all pages of second document into result document.
           for (int pageIndex = FIRST_PAGE_INDEX; pageIndex < igSecondDocument.Pages.Count; pageIndex++)
               igResultDocument.Pages.Add(igSecondDocument.Pages[pageIndex].Clone());
           return igResultDocument;
       }

This method can be extended for any document type. The main rule that must be observed for copying pages from one document to another is that the type of the documents must be the same.