Merge Multiple PDF Files into One PDF using C# .NET

Merge PDF files in C#

Aspose.PDF for .NET is a feature-rich API for creating, editing, reading or converting PDF documents. Along with other PDF manipulation features, Aspose.PDF for .NET also allows you to combine or merge PDF files programmatically in C# or VB.NET. In this article, you will learn how to:

  • Merge two PDF files into a single PDF file in C#.
  • Merge multiple (more than two) PDF files in C#.
  • Merge two or more PDF files using file streams in C#.

Before we start, let’s first have a look at the installation methods of Aspose.PDF for .NET.

Installing Aspose.PDF for .NET

You can install the API either using NuGet Package Manager or the Package Manager Console in Visual Studio.

Installing via NuGet Package Manager

Merge multiple PDF files in C# .NET

Installing via Package Manager Console

PM> Install-Package Aspose.PDF

Once you have installed the package, you can start merging the PDF files.

Merge Two PDF Files into One PDF in C#

The process of merging two PDF files into a single PDF is as simple as pie and can be performed only in two steps.

The following is the code sample to merge two PDF files using C#.

Merge Multiple PDF Files in C#

In case you want to merge more than two PDF files, you can do it using a string array containing the paths of all the PDF files to be merged. The following are the steps to perform this operation.

The following code sample shows how to merge multiple PDF files in C#.

Merge Multiple PDF Files using Streams in C#

There might be the case when you are not dealing with the files located on the disk. Instead, you want to merge PDF files available in the form of streams. In such a case, you can merge the PDFs directly using the Stream objects in the overloaded PdfFileEditor.Concatenate() methods. The following code samples show how to merge PDF files using the Stream objects in C#.

Merge Two PDF Files using Stream Objects

Merge Multiple PDF Files using Stream Objects

In case you are interested to explore more about the Aspose.PDF for .NET, take a look at the documentation.