Merge Two or More PDFs in C#
Merge PDFs of all sizes and complexity with ease and confidence with IronPDF's Merge
method.
The PdfDocument.Merge
method joins two or more PDFs together into a single PDF document.
Use the PdfDocument.Merge
method in your C# projects to:
- Add cover pages or cover letters to existing PDFs programmatically,
- Merge PDFs converted from HTML documents
PdfDocument.Merge
can merge any number of PDFs together.
How to Merge PDF Files in C#
- Download IronPDF Library for C#
- Load or Create two or more PDF files using the
RenderHtmlAsPdf
method - Merge the PDF files using the
Merge
method - Secure the PDF with a digital signature optionally
- Save the new PDF file using the
SaveAs
method
More Details
To merge two PDF documents, specify both PDFs as separate arguments, as shown in line 17 of the featured example.
To merge more than two PDF files, substitute the two-argument method with its List
overload:
List<PdfDocument> pdfs = new List<PdfDocument>()
{
pdfdoc_a,
pdfdoc_b,
pdfdoc_c,
// ...
};
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("Merged.pdf");
List<PdfDocument> pdfs = new List<PdfDocument>()
{
pdfdoc_a,
pdfdoc_b,
pdfdoc_c,
// ...
};
var merged = PdfDocument.Merge(pdfs);
merged.SaveAs("Merged.pdf");
Dim pdfs As New List(Of PdfDocument)() From {pdfdoc_a, pdfdoc_b, pdfdoc_c}
Dim merged = PdfDocument.Merge(pdfs)
merged.SaveAs("Merged.pdf")