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 IronPDFMerge 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.
-
1Install IronPDF with NuGet Package Manager
-
2Copy and run this code snippet.
IronPdf.PdfDocument .Merge(IronPdf.PdfDocument.FromFile("file1.pdf"), IronPdf.PdfDocument.FromFile("file2.pdf")) .SaveAs("merged.pdf");C# -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (5 steps)

- Download IronPDF library for PDF document manipulation
- Load existing or create a PDF from HTML string, file or URL
- Merge two PDF files in C# with
Mergemethod - Split a PDF file by pages utilizing the
CopyPageandCopyPagesmethods - Save the PDF document to the desired location
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.
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");Imports IronPdf
' Two paged PDF
Private Const html_a As String = "<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
Private Const html_b As String = "<p> [PDF_B] </p>
<p> [PDF_B] 1st Page </p>
<div style = 'page-break-after: always;' ></div>
<p> [PDF_B] 2nd Page</p>"
Private renderer = New ChromePdfRenderer()
Private pdfdoc_a = renderer.RenderHtmlAsPdf(html_a)
Private pdfdoc_b = renderer.RenderHtmlAsPdf(html_b)
' Four paged PDF
Private merged = PdfDocument.Merge(pdfdoc_a, pdfdoc_b)
merged.SaveAs("Merged.pdf")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:
- Batch Processing: Merge hundreds of PDFs programmatically using loops and collections
- Conditional Merging: Combine PDFs based on business logic or metadata criteria
- Template Integration: Merge dynamic content with pre-designed PDF templates
- 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.
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");Imports IronPdf
' Load an existing PDF document from a file.
Private pdf As PdfDocument = 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.
Private pageWidth As Integer = 250 ' Width of each page in the grid
Private pageHeight As Integer = 250 ' Height of each page in the grid
Private rows As Integer = 2 ' Number of rows in the grid
Private columns As Integer = 2 ' Number of columns in the grid
' Combine the pages of the PDF document into a single page with specified dimensions.
Private combinedPages As PdfDocument = pdf.CombinePages(pageWidth, pageHeight, rows, columns)
' Save the combined document as a new PDF file.
combinedPages.SaveAs("combinedPages.pdf")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:
pageWidth: Individual page width in millimeters within the gridpageHeight: Individual page height in millimeters within the gridrows: Number of horizontal rows in the grid layoutcolumns: Number of vertical columns in the grid layout
For custom page sizes, refer to our guide on custom paper size configuration.
The IronSuite play a crucial role in our operations. These are tools that increase efficiencies across the business including creating floor plans and improving inventory management.
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.
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");Imports IronPdf
' We will use the 4-page PDF from the Merge example above:
Private pdf = PdfDocument.FromFile("Merged.pdf")
' Takes only the first page into a new PDF
Private page1doc = pdf.CopyPage(0)
page1doc.SaveAs("Page1Only.pdf")
' Take the pages 2 & 3 (Note: index starts at 0)
Dim page23doc = pdf.CopyPages(1, 2)
page23doc.SaveAs("Pages2to3.pdf")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");Imports IronPdf
' Load a PDF document
Dim sourcePdf = PdfDocument.FromFile("LargeDocument.pdf")
' Extract cover page (first page)
Dim coverPage = sourcePdf.CopyPage(0)
coverPage.SaveAs("CoverPage.pdf")
' Extract table of contents (pages 2-5)
Dim tableOfContents = sourcePdf.CopyPages(1, 4)
tableOfContents.SaveAs("TableOfContents.pdf")
' Extract specific chapter (pages 20-35)
Dim chapter3 = sourcePdf.CopyPages(19, 34)
chapter3.SaveAs("Chapter3.pdf")
' Create a custom selection by merging specific pages
Dim customSelection = PdfDocument.Merge( _
sourcePdf.CopyPage(0), ' Cover
sourcePdf.CopyPages(5, 7), ' Executive Summary
sourcePdf.CopyPage(50) ' Conclusion
)
customSelection.SaveAs("ExecutiveBrief.pdf")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 can I merge PDF files using IronPDF in C#?
IronPDF provides a simple `Merge()` method to combine multiple PDF files into a single document. This method streamlines the merging process for C# developers, allowing them to integrate merging functionality into their .NET applications with minimal code.
What is the difference between the `CopyPage` and `CopyPages` methods in IronPDF?
`CopyPage(int pageIndex)` extracts a single page from a PDF at the specified zero-based index, whereas `CopyPages(int startIndex, int endIndex)` extracts a range of pages from a PDF document.
What are some common use cases for merging PDFs with IronPDF?
Common use cases include consolidating departmental reports into single executive summaries, merging invoices with supporting documents for simplification, and combining contracts, addendums, and signatures into legally compliant documents.
How do I split a PDF document using IronPDF?
Splitting a PDF in IronPDF can be done using the `CopyPage` and `CopyPages` methods. You can extract single pages or entire sections and save them as separate PDF files, allowing for flexible document management.
When should I consider using PDF splitting with IronPDF?
PDF splitting is beneficial when selectively distributing document sections, managing file sizes for email attachments, extracting specific chapters or sections, organizing archives, or processing individual forms.
Why might I use the `CombinePages` method in IronPDF?
The `CombinePages` method is ideal for creating thumbnail views, comparison sheets, optimizing print layouts, or generating handouts with multiple slides per page, all with customizable grid dimensions.
Can IronPDF handle merging PDFs from different sources?
Yes, IronPDF supports cross-format merging that allows combining PDFs created from HTML strings, URLs, images, or other content sources, offering flexible integration in diverse scenarios.
How can I customize the layout of combined pages using IronPDF?
When using the `CombinePages` method, you can specify the width, height, number of rows, and columns for the grid layout. This allows precise customization for creating specific page arrangements or visual preps.
What coding example demonstrates merging PDFs with IronPDF?
An example is: `IronPdf.PdfDocument.Merge(IronPdf.PdfDocument.FromFile("file1.pdf"), IronPdf.PdfDocument.FromFile("file2.pdf")).SaveAs("merged.pdf");` which combines two PDF files into one.
What are the benefits of using IronPDF for document management in C#?
IronPDF enhances document management by offering easy-to-use methods for merging and splitting PDFs, managing document layout, and ensuring efficient consolidation or distribution across various business needs.

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.