Cómo fusionar o dividir archivos PDF en C# | Tutorial de IronPDF

How to Merge or Split PDFs

This article was translated from English: Does it need improvement?
Translated
View the article in English

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

Effortlessly merge multiple PDF files into a single document using IronPDF. With just 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 with ease and efficiency.

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


Merge PDFs Example

In the following demonstration, we will initialize two two-paged HTML strings, render them as separate PDFs with IronPDF, and then merge them:

: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");
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")
$vbLabelText   $csharpLabel

Result

This is the file that the code produced:


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.

: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");
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")
$vbLabelText   $csharpLabel

Result


Split PDF Example

In the following demonstration, we will split the multi-page PDF document from the previous example.

: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");
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")
$vbLabelText   $csharpLabel

So this code saves two files:

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

Results

These are the two files produced:

Page1Only.pdf

Pages2to3.pdf

Ready to see what else you can do? Check out our tutorial page here: Organize PDFs

Preguntas Frecuentes

¿Cómo fusiono archivos PDF en C#?

Para fusionar archivos PDF en C#, puede usar el método Merge proporcionado por IronPDF. Primero, cargue o cree los documentos PDF, aplique el método Merge y guarde el documento combinado.

¿Cuál es el proceso para dividir un documento PDF en C#?

Puede dividir un documento PDF en C# usando IronPDF empleando los métodos CopyPage y CopyPages. Estos métodos le permiten extraer páginas específicas y guardarlas como archivos PDF separados.

¿Puedo combinar múltiples páginas PDF en una sola página?

Sí, con el método CombinePages de IronPDF, puede combinar múltiples páginas PDF en una sola página. Necesitará especificar las dimensiones y el diseño, como el número de filas y columnas.

¿Cómo puedo crear un PDF desde una cadena HTML en C#?

Puede crear un PDF desde una cadena HTML en C# usando IronPDF al renderizar la cadena HTML en un documento PDF. Esto se hace cargando el contenido HTML en el renderizador de IronPDF.

¿Cuáles son los pasos para comenzar a usar una biblioteca PDF en un proyecto de C#?

Para comenzar a usar una biblioteca PDF en un proyecto de C#, descargue IronPDF desde un gestor de paquetes como NuGet, luego integre en su proyecto. Puede crear y manipular documentos PDF usando los métodos de IronPDF.

¿Hay una prueba gratuita disponible para la biblioteca PDF?

Sí, IronPDF ofrece una versión de prueba gratuita. Puede descargarla desde el sitio web oficial o un gestor de paquetes como NuGet para empezar a experimentar con las funcionalidades PDF.

¿Cómo extraigo una sola página de un PDF en C#?

Para extraer una sola página de un PDF en C#, use el método CopyPage de IronPDF para seleccionar la página deseada y guárdela como un nuevo archivo PDF.

¿Cuáles son algunas aplicaciones prácticas para la fusión de PDFs?

La fusión de PDFs es útil para combinar documentos relacionados, como fusionar múltiples facturas o informes en un solo archivo para facilitar el intercambio y la organización.

¿Cómo puedo convertir una página web a un documento PDF?

Puede convertir una página web en un documento PDF usando IronPDF cargando la URL en el renderizador de IronPDF, que luego crea un PDF con el contenido de la página web.

¿Qué código C# se necesita para dividir un PDF de varias páginas en archivos separados?

Para dividir un PDF de varias páginas en archivos separados usando IronPDF, utilice los métodos CopyPage o CopyPages para extraer las páginas que necesita y guardarlas individualmente.

¿IronPDF es totalmente compatible con .NET 10 para fusionar y dividir archivos PDF?

Sí. IronPDF es totalmente compatible con .NET 10, al igual que las versiones anteriores. Ofrece funciones de fusión y división de PDF (incluidas Merge , CopyPage , CopyPages y CombinePages ) listas para usar en proyectos .NET 10 sin necesidad de soluciones alternativas. Puede usar IronPDF en .NET 10 para aplicaciones de escritorio, web, en la nube o de consola.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado