How to Merge or Split PDF Files in C# | IronPDF Tutorial

How to Merge or Split PDFs in C# with IronPDF

IronPDF enables C# developers to merge multiple PDF files into one document or split PDFs into separate files using simple methods like Merge() for combining and CopyPage()/CopyPages() for splitting, streamlining document management in .NET applications.

Merging multiple PDF files into one can be highly useful in various scenarios. For instance, you can consolidate similar documents such as resumes into a single file instead of sharing multiple files. This article guides you through the process of merging multiple PDF files using C#. IronPDF simplifies PDF splitting and merging with intuitive method calls within your C# application. Below, we'll walk you through all the page manipulation functionalities.

Quickstart: Merge PDFs with IronPDF

Merge multiple PDF files into a single document using IronPDF. With a few lines of code, developers can integrate PDF merging functionality into their C# applications. This quick guide demonstrates how to use the IronPDF library's Merge method to combine PDFs, streamlining document management tasks.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    IronPdf.PdfDocument
        .Merge(IronPdf.PdfDocument.FromFile("file1.pdf"), IronPdf.PdfDocument.FromFile("file2.pdf"))
        .SaveAs("merged.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


How Do I Merge PDFs in C#?

In the following demonstration, we will initialize two two-paged HTML strings, render them as separate PDFs with IronPDF, and then merge them. This approach is particularly useful when you need to convert HTML to PDF and combine multiple HTML documents into a single PDF output.

:path=/static-assets/pdf/content-code-examples/how-to/merge-or-split-pdfs-merge.cs
using IronPdf;

// Two paged PDF
const string html_a =
    @"<p> [PDF_A] </p>
    <p> [PDF_A] 1st Page </p>
    <div style = 'page-break-after: always;' ></div>
    <p> [PDF_A] 2nd Page</p>";

// Two paged PDF
const string html_b =
    @"<p> [PDF_B] </p>
    <p> [PDF_B] 1st Page </p>
    <div style = 'page-break-after: always;' ></div>
    <p> [PDF_B] 2nd Page</p>";

var renderer = new ChromePdfRenderer();

var pdfdoc_a = renderer.RenderHtmlAsPdf(html_a);
var pdfdoc_b = renderer.RenderHtmlAsPdf(html_b);

// Four paged PDF
var merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b);
merged.SaveAs("Merged.pdf");
$vbLabelText   $csharpLabel

The code above demonstrates how to use page breaks effectively to create multi-page PDFs before merging. The page-break-after: always CSS property ensures each section starts on a new page.

What Does the Merged PDF Look Like?

This is the file that the code produced:

When Should I Use PDF Merging?

PDF merging is particularly valuable in enterprise environments where document consolidation improves workflow efficiency. Common applications include:

  • Report Generation: Combine multiple departmental reports into comprehensive executive summaries using PDF report generation
  • Invoice Processing: Merge customer invoices with supporting documentation for simplified billing workflows
  • Legal Documentation: Consolidate contracts, addendums, and signatures into single legal documents
  • Educational Materials: Combine course materials, assignments, and resources into comprehensive study guides

What Are Common Merge Scenarios?

Beyond basic file combination, IronPDF supports advanced merging scenarios:

  1. Batch Processing: Merge hundreds of PDFs programmatically using loops and collections
  2. Conditional Merging: Combine PDFs based on business logic or metadata criteria
  3. Template Integration: Merge dynamic content with pre-designed PDF templates
  4. Cross-Format Merging: Combine PDFs created from different sources like HTML strings, URLs, or images

How Can I Combine PDF Pages?

Use the CombinePages method to combine multiple PDF pages into a single page. The method requires the width, height, number of rows, and number of columns. This feature is especially useful for creating thumbnails, contact sheets, or multi-page previews.

:path=/static-assets/pdf/content-code-examples/how-to/merge-or-split-pdfs-combine.cs
using IronPdf;

// Load an existing PDF document from a file.
PdfDocument pdf = PdfDocument.FromFile("Merged.pdf");

// Combine pages of the loaded PDF into a grid with specified dimensions.
// The parameters for CombinePages are the width and height of each page
// in millimeters followed by the number of rows and columns to create the grid.
int pageWidth = 250;  // Width of each page in the grid
int pageHeight = 250; // Height of each page in the grid
int rows = 2;         // Number of rows in the grid
int columns = 2;      // Number of columns in the grid

// Combine the pages of the PDF document into a single page with specified dimensions.
PdfDocument combinedPages = pdf.CombinePages(pageWidth, pageHeight, rows, columns);

// Save the combined document as a new PDF file.
combinedPages.SaveAs("combinedPages.pdf");
$vbLabelText   $csharpLabel

What Does the Combined Page Look Like?

Why Combine Pages Into a Grid?

Combining pages into a grid layout serves multiple purposes:

  • Document Previews: Create thumbnail views of multi-page documents for quick visual scanning
  • Comparison Sheets: Display multiple versions side-by-side for easy comparison
  • Print Optimization: Reduce paper usage by fitting multiple pages on a single sheet
  • Presentation Materials: Create handouts with multiple slides per page

What Are the Parameters for CombinePages?

The CombinePages method accepts four essential parameters:

  1. pageWidth: Individual page width in millimeters within the grid
  2. pageHeight: Individual page height in millimeters within the grid
  3. rows: Number of horizontal rows in the grid layout
  4. columns: Number of vertical columns in the grid layout

For custom page sizes, refer to our guide on custom paper size configuration.


How Do I Split PDFs in C#?

In the following demonstration, we will split the multi-page PDF document from the previous example. PDF splitting is essential for extracting specific pages, creating document excerpts, or distributing individual sections to different recipients.

:path=/static-assets/pdf/content-code-examples/how-to/merge-or-split-pdfs-split.cs
using IronPdf;

// We will use the 4-page PDF from the Merge example above:
var pdf = PdfDocument.FromFile("Merged.pdf");

// Takes only the first page into a new PDF
var page1doc = pdf.CopyPage(0);
page1doc.SaveAs("Page1Only.pdf");

// Take the pages 2 & 3 (Note: index starts at 0)
var page23doc = pdf.CopyPages(1, 2);
page23doc.SaveAs("Pages2to3.pdf");
$vbLabelText   $csharpLabel

This code saves two files:

  • Page1Only.pdf (Only the first page)
  • Pages2to3.pdf (Second to Third page)

What Do the Split PDFs Look Like?

These are the two files produced:

Page1Only.pdf

Pages2to3.pdf

When Should I Split PDFs?

PDF splitting offers numerous advantages in document management:

  • Selective Distribution: Share only relevant pages with specific stakeholders
  • File Size Management: Break large PDFs into manageable chunks for email attachments
  • Chapter Extraction: Extract individual chapters from books or manuals
  • Form Processing: Separate completed forms from instruction pages
  • Archive Organization: Split documents by date, department, or category

For more advanced page manipulation, explore our guide on adding, copying, and deleting pages.

What's the Difference Between CopyPage and CopyPages?

Understanding the distinction between these methods is crucial for efficient PDF manipulation:

  • CopyPage(int pageIndex): Extracts a single page at the specified index (zero-based)
  • CopyPages(int startIndex, int endIndex): Extracts a range of pages inclusively

Here's an advanced example demonstrating both methods:

using IronPdf;

// Load a PDF document
var sourcePdf = PdfDocument.FromFile("LargeDocument.pdf");

// Extract cover page (first page)
var coverPage = sourcePdf.CopyPage(0);
coverPage.SaveAs("CoverPage.pdf");

// Extract table of contents (pages 2-5)
var tableOfContents = sourcePdf.CopyPages(1, 4);
tableOfContents.SaveAs("TableOfContents.pdf");

// Extract specific chapter (pages 20-35)
var chapter3 = sourcePdf.CopyPages(19, 34);
chapter3.SaveAs("Chapter3.pdf");

// Create a custom selection by merging specific pages
var customSelection = PdfDocument.Merge(
    sourcePdf.CopyPage(0),      // Cover
    sourcePdf.CopyPages(5, 7),  // Executive Summary
    sourcePdf.CopyPage(50)      // Conclusion
);
customSelection.SaveAs("ExecutiveBrief.pdf");
using IronPdf;

// Load a PDF document
var sourcePdf = PdfDocument.FromFile("LargeDocument.pdf");

// Extract cover page (first page)
var coverPage = sourcePdf.CopyPage(0);
coverPage.SaveAs("CoverPage.pdf");

// Extract table of contents (pages 2-5)
var tableOfContents = sourcePdf.CopyPages(1, 4);
tableOfContents.SaveAs("TableOfContents.pdf");

// Extract specific chapter (pages 20-35)
var chapter3 = sourcePdf.CopyPages(19, 34);
chapter3.SaveAs("Chapter3.pdf");

// Create a custom selection by merging specific pages
var customSelection = PdfDocument.Merge(
    sourcePdf.CopyPage(0),      // Cover
    sourcePdf.CopyPages(5, 7),  // Executive Summary
    sourcePdf.CopyPage(50)      // Conclusion
);
customSelection.SaveAs("ExecutiveBrief.pdf");
$vbLabelText   $csharpLabel

This example showcases how to create custom document compilations by combining split operations with merge functionality, perfect for creating executive briefings or customized reports.

Ready to see what else you can do? Check out our tutorial page here: Organize PDFs for comprehensive PDF organization techniques including metadata management, bookmark creation, and advanced page manipulation strategies.

Frequently Asked Questions

How do I merge multiple PDF files into one using C#?

With IronPDF, you can merge multiple PDF files using the simple Merge() method. Just call IronPdf.PdfDocument.Merge() and pass in the PDF documents you want to combine, then save the result with SaveAs(). This allows you to consolidate multiple PDFs into a single document with just a few lines of C# code.

What is the quickest way to combine two PDFs?

The quickest way is using IronPDF's one-line merge functionality: IronPdf.PdfDocument.Merge(IronPdf.PdfDocument.FromFile("file1.pdf"), IronPdf.PdfDocument.FromFile("file2.pdf")).SaveAs("merged.pdf"). This single line of code loads two PDFs and merges them into one.

Can I split PDF files by extracting specific pages?

Yes, IronPDF provides the CopyPage() and CopyPages() methods for splitting PDFs. These methods allow you to extract individual pages or ranges of pages from existing PDF documents and save them as separate files, making it easy to split large PDFs programmatically.

Is it possible to merge HTML content into PDFs?

Absolutely! IronPDF allows you to first convert HTML strings to PDF using its HTML-to-PDF rendering capabilities, then merge these generated PDFs together. This is particularly useful when you need to combine multiple HTML documents or reports into a single PDF output.

What are common use cases for PDF merging in enterprise applications?

IronPDF's merging capabilities are commonly used for report generation (combining departmental reports), invoice processing (merging invoices with supporting documents), and legal document compilation. These features help streamline document management workflows in .NET applications.

How do I ensure proper page breaks when merging PDFs from HTML?

When using IronPDF to convert HTML to PDF before merging, you can use the CSS property 'page-break-after: always' to ensure each section starts on a new page. This gives you precise control over page layout in your merged PDF documents.

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
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released