Merge PDF files in C#

Combining multiple PDF files into a single document is a frequent requirement in various use cases like organizing resumes or consolidating reports. This article demonstrates the usage of Aspose.PDF for .NET to merge PDFs efficiently, offering both simplicity and flexibility.


Topics Covered:


C# Library to Merge PDF Files

Aspose.PDF for .NET is a robust library providing tools for creating, editing, and merging PDF files. Install it via NuGet:

PM> Install-Package Aspose.PDF

With Aspose.PDF for .NET, developers can merge PDFs seamlessly, work with file streams, and manipulate PDFs programmatically.


How to Merge Two PDF Files in C#

The process of merging two PDFs involves:

  1. Creating an instance of the PdfFileEditor class.
  2. Using the Concatenate method to merge the files.

Example Code:


Merge Multiple PDF Files in C#

To merge more than two PDFs:

  1. Create an array of file paths.
  2. Use the Concatenate method with the array.

Example Code:


Combine PDF Files Using File Streams

When working with PDF streams instead of file paths:

  1. Use the Concatenate method with Stream objects.
  2. Ensure the streams are readable and positioned correctly.

Example Code:


Conclusion

Aspose.PDF for .NET simplifies merging multiple PDF files, whether working with file paths or streams. For more information, explore the Aspose.PDF documentation.