.NET PDF Merge Tasks with IronPDF: A Complete C# Guide

Combining multiple PDF files into a single PDF document is extremely easy with IronPDF. Whether building console applications, Windows Forms samples, or a web service, this .NET PDF library delivers simple syntax and easy integration for merging PDF documents programmatically. This article demonstrates how to merge PDF files, combine existing PDF documents, and save the resulted PDF document—all with minimal code. The merged document preserves all pages, formatting, and content from your source files.
Get started with a free trial to add PDF merge capabilities to your .NET application today.
How Can You Merge PDF Documents Programmatically?
The PdfDocument.Merge method provides the simplest way to merge multiple PDF files into a single PDF. This merging PDF approach works seamlessly across .NET Framework, .NET Core, and .NET 8+ projects with no additional installation required beyond the NuGet package. The tool makes it extremely easy to create merged documents from separate files.
Input Invoice One

Input Invoice Two

using IronPdf;
class Program
{
static void Main(string[] args)
{
// Load two input PDF files from disk
PdfDocument pdfA = PdfDocument.FromFile("invoice_one.pdf");
PdfDocument pdfB = PdfDocument.FromFile("invoice_two.pdf");
// Merge PDF documents into a single PDF
PdfDocument merged = PdfDocument.Merge(pdfA, pdfB);
// Save the merged document
merged.SaveAs("combined_invoices.pdf");
}
}using IronPdf;
class Program
{
static void Main(string[] args)
{
// Load two input PDF files from disk
PdfDocument pdfA = PdfDocument.FromFile("invoice_one.pdf");
PdfDocument pdfB = PdfDocument.FromFile("invoice_two.pdf");
// Merge PDF documents into a single PDF
PdfDocument merged = PdfDocument.Merge(pdfA, pdfB);
// Save the merged document
merged.SaveAs("combined_invoices.pdf");
}
}Output

The Merge method accepts two input PDF files and returns a new PdfDocument containing all PDF pages from both source documents. The merged document preserves the original formatting, images, and content from each input file. Once you have the merged files, you can save the output PDF file to any location or process it further—edit pages, convert formats, or delete unwanted content as needed. This merging PDF approach works with documents of any size.
What Is the Best Way to Merge Multiple PDF Files?
When you need to merge multiple PDF documents beyond just two, IronPDF accepts a list of PDF files. This code sample shows how to combine multiple PDF files from different PDF documents into one consolidated file using the merging PDF tool:
using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
// Create a list to hold existing PDF documents
List<PdfDocument> pdfsToMerge = new List<PdfDocument>
{
PdfDocument.FromFile("report_q1.pdf"),
PdfDocument.FromFile("report_q2.pdf"),
PdfDocument.FromFile("report_q3.pdf"),
PdfDocument.FromFile("report_q4.pdf")
};
// Merge multiple PDF files into a single PDF document
PdfDocument merged = PdfDocument.Merge(pdfsToMerge);
// Save the new PDF document
merged.SaveAs("annual_report.pdf");
}
}using IronPdf;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
// Create a list to hold existing PDF documents
List<PdfDocument> pdfsToMerge = new List<PdfDocument>
{
PdfDocument.FromFile("report_q1.pdf"),
PdfDocument.FromFile("report_q2.pdf"),
PdfDocument.FromFile("report_q3.pdf"),
PdfDocument.FromFile("report_q4.pdf")
};
// Merge multiple PDF files into a single PDF document
PdfDocument merged = PdfDocument.Merge(pdfsToMerge);
// Save the new PDF document
merged.SaveAs("annual_report.pdf");
}
}Merged PDF Document

This method to merge multiple PDF files scales efficiently whether processing three files or thirty documents. The tool handles merging PDF documents while maintaining document integrity across all pages, and works identically in Windows Forms, console applications, or server-delivered environments with XCopy deployment support. Every merged file retains its original structure.
How Can You Combine Existing PDF Documents with MemoryStream?
For scenarios requiring in-memory processing—such as a command line utility or web service—you can merge PDF files without writing documents to disk. Using a new MemoryStream approach, this merging PDF tool keeps everything in memory and can create output documents dynamically:
using IronPdf;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Load PDF files into memory streams
byte[] firstFileBytes = File.ReadAllBytes("contract_part1.pdf");
byte[] secondFileBytes = File.ReadAllBytes("contract_part2.pdf");
// Create PDF documents from byte arrays
PdfDocument doc1 = new PdfDocument(firstFileBytes);
PdfDocument doc2 = new PdfDocument(secondFileBytes);
// Merge and export to MemoryStream
PdfDocument merged = PdfDocument.Merge(doc1, doc2);
// Write to a new MemoryStream for further processing
MemoryStream outputStream = merged.Stream;
// Save the merged document
merged.SaveAs("merged_contract.pdf");
}
}using IronPdf;
using System.IO;
class Program
{
static void Main(string[] args)
{
// Load PDF files into memory streams
byte[] firstFileBytes = File.ReadAllBytes("contract_part1.pdf");
byte[] secondFileBytes = File.ReadAllBytes("contract_part2.pdf");
// Create PDF documents from byte arrays
PdfDocument doc1 = new PdfDocument(firstFileBytes);
PdfDocument doc2 = new PdfDocument(secondFileBytes);
// Merge and export to MemoryStream
PdfDocument merged = PdfDocument.Merge(doc1, doc2);
// Write to a new MemoryStream for further processing
MemoryStream outputStream = merged.Stream;
// Save the merged document
merged.SaveAs("merged_contract.pdf");
}
}Merged Contract File

This example demonstrates how merging multiple PDF documents works within the same assembly without temporary files. The process supports string paths, byte arrays, and streams interchangeably, making it ideal for processing multiple PDFs in automated workflows where files exist only in memory.
How Are Bookmarks and Security Handled in Merged PDF Files?
When you merge PDF files, IronPDF preserves file merge PDF bookmarks from the original documents. The merged document retains navigation elements across all pages, making it easy for readers to jump between sections from different PDF documents. All merged files maintain their bookmarks in the final output.
To password protect the resulted PDF document after merging:
// Apply security to the merged document
merged.SecuritySettings.UserPassword = "reader123";
merged.SecuritySettings.OwnerPassword = "admin456";
merged.SaveAs("secured_merged.pdf");// Apply security to the merged document
merged.SecuritySettings.UserPassword = "reader123";
merged.SecuritySettings.OwnerPassword = "admin456";
merged.SaveAs("secured_merged.pdf");You can also adjust the compression level to optimize file size, set the creation date metadata, or configure merged document rights to control what users can do with the output PDF file. These security features help create professional documents that meet your organization's requirements.
What Are Common Use Cases for PDF Merging?
PDF merge capabilities serve many practical scenarios in a .NET application when working with multiple PDF documents:
- Financial Reports: Combine existing PDF documents from quarterly statements into annual reports with merged pages
- Legal Documentation: Append contracts, amendments, and signatures into a single PDF file for archival
- Invoice Consolidation: Merge elements from multiple PDFs into one billing document with all pages combined
- Document Archival: Create consolidated records by merging PDF documents systematically across files
IronPDF also supports the ability to convert DOCX files to PDF before merging, allowing you to combine multiple PDFs that originated from different formats. The .NET assembly provides simple copy operations to extract specific pages before or after the merge process, giving you complete control over which documents and pages appear in your final merged output.
Conclusion: Streamlined PDF Merging in .NET
The examples throughout this article demonstrate just how easy and efficient it is to handle complex .NET PDF merge tasks within any C# or .NET application using IronPDF.
By utilizing the simple PdfDocument.Merge method, developers can quickly combine multiple PDF files, whether two separate documents, an entire list of files, or even documents loaded from MemoryStream, into a single, consolidated PDF.
- ✅ Simplicity: Minimal, clear C# code is required to achieve powerful results.
- ✅ Integrity: All original content, formatting, and bookmarks are preserved in the merged file.
- ✅ Flexibility: The approach works seamlessly across .NET Framework, .NET Core, and .NET 8+ projects.
- ✅ Functionality: Beyond merging, IronPDF offers robust features like password protection and further document manipulation, creating professional, secure, and well-organized output documents for diverse use cases—from financial reporting to legal archiving.
Ready to add PDF merge capabilities to your project? IronPDF makes merging PDF files in any .NET application straightforward with its intuitive API. The tool works across all major .NET platforms with the same simple syntax demonstrated in these code examples, handling documents and files of any complexity.
Frequently Asked Questions
How can I merge PDF files using C#?
You can merge PDF files in C# using IronPDF by loading existing PDF documents and combining them into a single file. This is done programmatically, allowing for efficient and automated merging of files.
What are the benefits of using IronPDF for merging PDFs?
IronPDF offers a user-friendly API to merge PDFs, handle bookmarks, and even add password protection to merged files. It is a powerful tool for developers looking to integrate PDF manipulation into their .NET applications.
Can I preserve bookmarks when merging PDFs with IronPDF?
Yes, IronPDF allows you to maintain bookmarks from the original documents when merging PDFs, ensuring that the navigational structure of your documents is retained.
Is it possible to password protect merged PDF files using IronPDF?
IronPDF enables you to add password protection to merged PDF files, providing an extra layer of security to your documents.
Does IronPDF support merging PDFs with different page sizes?
Yes, IronPDF can handle merging PDFs with varying page sizes, ensuring that the final document maintains the integrity of the original files.
What file formats are supported by IronPDF for merging?
IronPDF primarily supports PDF files for merging, allowing you to combine multiple PDFs into a single document.
Is there a free trial available for IronPDF?
Yes, IronPDF offers a free trial, allowing developers to test its features, including PDF merging capabilities, before committing to a purchase.
Can I use IronPDF to merge encrypted PDFs?
IronPDF can merge encrypted PDFs, provided you have the necessary passwords to access the content of these files.









