Merge PDF files in C# and VB.NET
With GemBox.Pdf, you can merge PDF files into one PDF file in your C# or VB.NET application.
PDF pages are self-contained entities (their appearance is fully defined by their content stream and the associated resources, and their annotations primarily define their interactivity. That’s why you can easily clone them to other PDF files.
To merge PDF files, you simply need to clone all of their pages into a destination PDF file.
The following example shows how you can merge (concatenate) PDF files.

using GemBox.Pdf;
class Program
{
static void Main()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// List of source file names.
var fileNames = new string[]
{
"%#MergeFile01.pdf%",
"%#MergeFile02.pdf%",
"%#MergeFile03.pdf%"
};
using (var document = new PdfDocument())
{
// Merge multiple PDF files into single PDF by loading source documents
// and cloning all their pages to destination document.
foreach (var fileName in fileNames)
using (var source = PdfDocument.Load(fileName))
document.Pages.Kids.AddClone(source.Pages);
document.Save("Merge Files.pdf");
}
}
}
Imports GemBox.Pdf
Module Program
Sub Main()
' If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' List of source file names.
Dim fileNames = New String() _
{
"%#MergeFile01.pdf%",
"%#MergeFile02.pdf%",
"%#MergeFile03.pdf%"
}
Using document = New PdfDocument()
' Merge multiple PDF files into single PDF by loading source documents
' and cloning all their pages to destination document.
For Each fileName In fileNames
Using source = PdfDocument.Load(fileName)
document.Pages.Kids.AddClone(source.Pages)
End Using
Next
document.Save("Merge Files.pdf")
End Using
End Sub
End Module
In the example above, you can see that the source PDF files are combined to clone the pages to a new PdfDocument
, and then save it to a PDF file.
If you want to clone a PDF page to an existing PdfDocument
, we recommend seeing the Cloning example.
See also
Next steps
Published: December 13, 2018 | Modified: September 21, 2021 | Author: Damir Stipinovic