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) in a single file or you may want to share a single file instead of a bulk. To meet the above-mentioned or similar requirements, in this article, you will learn how to merge multiple PDF files in C#.

C# Library to Merge PDF Files

To merge PDF files, we will use Aspose.PDF for .NET. It is a feature-rich library for creating, editing, reading, or converting PDF documents. Along with other PDF manipulation features, Aspose.PDF for .NET allows you to merge PDF files with ease. Not only this but you can get a free license and manipulate PDFs 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#

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 PDF files in C#.

C# Merge Multiple PDF Files

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#.

C# Combine Multiple PDF Files using Streams

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.

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

In this article, you have learned how to merge PDF files programmatically in C# .NET. 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