Merge multiple PDF files

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Going Deeper > Document Engines > Working with PDF > Enhancement >

Merge multiple PDF files

In this section we present example code to merge multiple PDF files into one. Before proceeding further please make sure that the prerequisite steps as listed in the Document Engines parent topic are followed.

Note that if you need to merge multiple documents of PDF and other formats then you can use the DocumentConverter component.

 

Given below is the sample code.

 

// List of files to be merged
var files = new List<string>();
files.Add(@"document1.pdf");
files.Add(@"document2.pdf");
files.Add(@"document3.pdf");
files.Add(@"document4.pdf");
using (var pdfDoc = new PDF())
{
   foreach (var filePath in files)
   {
      pdfDoc.Merge(filePath);
   }
 
   pdfDoc.Save(@"merged.pdf");
}