Merge Multiple PDF Files using C# .NET

Merge PDF files in C#

Merging multiple PDF files into a single PDF could be useful in various scenarios. For example, you can keep similar documents (i.e. resumes) into a single file or you may want to share a single file instead of a bulk. In order to meet the above-mentioned or similar requirements, in this article, you will learn how to merge multiple PDF files in C#.

Merge PDFs using C# PDF API – Free Download

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. You can download the API or install it either by using the 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

Merge Two PDF Files using 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.

Merge PDF Files using Streams in C#

There might be a 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.

Merge Two PDF Files using Stream Objects

Merge Multiple PDF Files using Stream Objects

Conclusion

In this article, you have learned how to merge PDF files programmatically using C#. Furthermore, this article explicitly discusses how to merge two PDF files or multiple (more than two) PDF files into a single PDF. In case you are interested to explore more about the Aspose.PDF for .NET, take a look at the documentation.

See Also