
Merging multiple PDF files into a single PDF is useful in many scenarios. For example, you can combine similar documents such as resumes into one file, or share a single PDF instead of many. This article shows how to merge multiple PDF files in C#.
- C# API to Merge PDFs
- Merge two PDF files using C#
- Merge multiple (more than two) PDF files in C#
- Combine PDF files using file streams
C# Library to Merge PDF Files
We will use Aspose.PDF for .NET to merge PDF files. This feature‑rich library supports creating, editing, reading, and converting PDFs. It also lets you merge PDFs easily and, with a free license, you can work without limitations.
You can download the library or install it using NuGet.
PM> Install-Package Aspose.PDF
Info: Aspose.Slides for .NET is another Aspose API that allows you to merge PDF files. You can also use this product to merge PPT, join jpg or other images to each other, and also combine HTML documents.
How to Merge Two PDF Files in C#
Merging two PDF files into one is straightforward and requires only two steps.
- Create an instance of PdfFileEditor class.
- Call PdfFileEditor.Concatenate(string, string , string) method.
The following is the code sample to merge PDF files in C#.
C# Merge Multiple PDF Files
To merge more than two PDFs, use a string array with the paths of each file. Follow these steps.
- Create an instance of PdfFileEditor class.
- Create an array containing paths of the PDF files to be merged.
- Call PdfFileEditor.Concatenate(string[], string) method.
The following code sample shows how to merge multiple PDF files in C#.
C# Combine Multiple PDF Files using Streams
If the PDFs are not stored on disk but are available as streams, you can merge them directly using the overloaded PdfFileEditor.Concatenate() methods. The code samples below demonstrate this.
Combining Two PDF Files
Merging Multiple PDF Files
Free C# PDF Merger Library
You can get a free temporary license and merge PDF files without any limitations.
Conclusion
This article showed how to merge PDF files programmatically in C# .NET, covering both two‑file and multi‑file scenarios. To learn more about Aspose.PDF for .NET, see the documentation.