How to Merge/Combine PDF Files in C# — A Complete Guide

Andrew Wilson
2 min readApr 23, 2024

Merging PDF documents comes with many benefits, such as you can merge multiple related PDFs into a single document to make them easier to manage and share. Besides, combining separate PDF files into one can also help keep your digital files well-organized.

In this article, we will explore how to merge multiple PDF files into one using a Free .NET PDF library.

Free .NET Library for Merging PDFs

To get started, we’ll need to download the free library — Free Spire.PDF for .NET - via the below link or install it directly via Nuget.

The library is completely free that can be used for both commercial and personal purposes.

Merge Multiple PDFs into One (C# Code)

To combine or combine multiple PDF file into one, we can first specify the file paths of several PDF file and then call the PdfDocument.MergeFiles() method to merge them.

Merging PDFs with Free Spire.PDF for .NET is a simple process that requires only a few lines of code.

using System;
using Spire.Pdf;

namespace MergePDFs
{
class Program
{
static void Main(string[] args)
{
//Get the paths of the documents to be merged
String[] files = new String[] {
"C:\\Users\\Administrator\\Documents\\file1.pdf",
"C:\\Users\\Administrator\\Documents\\file2.pdf",
"C:\\Users\\Administrator\\Documents\\file3.pdf"};

//Merge these documents and return an object of PdfDocumentBase
PdfDocumentBase pdf = PdfDocument.MergeFiles(files);

//Save the result to a PDF file
pdf.Save("MergePDF.pdf", FileFormat.PDF);
}
}
}

Merge three PDFs:

C# merge PDF files

※ In addition to merging multiple PDF files, Spire.PDF for .NET also allows you to import a page or a page range from one PDF document to another.

To learn how to combine the selected pages from different PDF documents into a new PDF document, click on the link to view the tutorial.

--

--

Andrew Wilson

Explore C#, Java and Python solutions for processing Word/Excel/PowerPoint/PDF files.