Skip to footer content
USING IRONPDF

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

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 1 - Merge PDFs with IronPDF

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

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 2 - Input Invoice One

Input Invoice Two

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 3 - 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");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Output

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 4 - Combined PDF documents

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");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Merged PDF Document

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 5 - Newly merged output PDF file

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");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Merged Contract File

.NET PDF Merge Tasks with IronPDF: A Complete C# Guide: Image 6 - Merged Contract PDF document

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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

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.

Get stated with IronPDF now.
green arrow pointer
For production use, purchase a license that fits your team's needs. Explore additional features like splitting PDFs, adding headers and footers, or converting HTML to PDF for extended merging PDF capabilities.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More