A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: file_get_contents(http://103.13.28.148/cstovb/cstovb/): failed to open stream: HTTP request failed!

Filename: libraries/Converter.php

Line Number: 134

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 134
Function: file_get_contents

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: 8192

Message: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior

Filename: libraries/Converter.php

Line Number: 136

Backtrace:

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 136
Function: strpos

File: /var/www/ironpdf.com/application/libraries/Converter.php
Line: 92
Function: convert_cs_to_vb_with_vbconverter

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 1814
Function: convert_cs_to_vb

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 559
Function: render_cs_window

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 532
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 561
Function: {closure}

File: /var/www/ironpdf.com/application/libraries/MarkdownProcessor.php
Line: 28
Function: render_language_type

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 340
Function: processMarkdownViewContent

File: /var/www/ironpdf.com/application/controllers/Products/Blog.php
Line: 77
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

.NET Merge PDF: Combining Files with IronPDF (Developer Tutorial)Skip to footer content
USING IRONPDF

How to Merge PDF Files in .NET

How to Merge PDF Files in .NET: Figure 1 - multiple PDF icons converging into a single PDF

Combining multiple PDF files into a single new document is a common requirement in business applications. Whether you're consolidating reports, bundling invoices, or assembling documentation packages, the ability to merge PDF files programmatically saves time and reduces manual effort. IronPDF is a powerful PDF library that makes this process remarkably simple in .NET applications with just a few lines of code.

In this article, you'll learn how to merge PDF documents using IronPDF's straightforward API, from basic two-file combinations to handling several documents dynamically. The IronPDF library provides a robust solution to combine PDF files efficiently while maintaining document integrity. We'll utilize various features of the library, including creating a new string for HTML content and handling different sources.

How Do You Install IronPDF for .NET Merge PDF?

Getting started with IronPDF requires just a simple NuGet package installation. Open your Package Manager Console in Visual Studio and run:

Install-Package IronPdf

Once installed, add the IronPDF namespace to your C# file:

using IronPdf;
using IronPdf;
Imports IronPdf
$vbLabelText   $csharpLabel

That's all the setup needed. IronPDF handles all the complex PDF manipulation behind the scenes, letting you focus on your application logic. With the library installed, you're ready to start merging both existing and new PDF documents immediately. Note that this process is compatible with various operating systems, including Linux via .NET Core. For detailed installation guidance, visit the IronPDF installation documentation.

How to Merge Two PDF Documents?

The most basic merging scenario involves combining two existing or new PDFDocument objects. Here's how to accomplish this task:

using IronPdf;
class Program
{
    static void Main()
    {
        // Load the PDF documents
        var pdf1 = PdfDocument.FromFile("Invoice1.pdf");
        var pdf2 = PdfDocument.FromFile("Invoice2.pdf");
        // Merge the documents
    var merged = PdfDocument.Merge(pdf1, pdf2);
    // Save the merged document
    merged.SaveAs("Merged.pdf"); 
    }
}
using IronPdf;
class Program
{
    static void Main()
    {
        // Load the PDF documents
        var pdf1 = PdfDocument.FromFile("Invoice1.pdf");
        var pdf2 = PdfDocument.FromFile("Invoice2.pdf");
        // Merge the documents
    var merged = PdfDocument.Merge(pdf1, pdf2);
    // Save the merged document
    merged.SaveAs("Merged.pdf"); 
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This code demonstrates the simplicity of merging PDFs with IronPDF. The PdfDocument.FromFile() method loads existing PDF files into memory. These loaded documents become PdfDocument objects that can be manipulated programmatically.

The Merge() method takes two or more PdfDocument objects and combines them into a single PDF file. The PDF pages from the second document are appended after the pages of the first document, maintaining the original order and formatting of each page. Learn more about the Merge method in the API documentation.

Finally, SaveAs() writes the merged document to disk. The resulting PDF contains all pages from both source documents in sequence, ready for distribution or further processing.

Output

How to Merge PDF Files in .NET: Figure 2 - Unmerged PDF files vs. the final, merged PDF

How to Merge Multiple PDF Files?

Real-world applications often need to merge PDF files beyond just two documents. As we saw in the previous example, IronPDF can easily handle the merging of PDF files in just a couple lines of code. Now, we'll look at how IronPDF can handle this scenario elegantly using a List collection:

using IronPdf;
using System.Collections.Generic;
using System.IO;
class Program
{
    static void Main()
    {
        // Create a list to store PDF documents
        var files = new List<PdfDocument>();
        // Get all PDF files from a directory
        string[] fileNames = Directory.GetFiles(@"C:\Reports\", "*.pdf");
        // Load each PDF file
        foreach (var fileName in fileNames)
        {
            files.Add(PdfDocument.FromFile(fileName));
        }
        // Merge all PDFs into one
        var merged = PdfDocument.Merge(pdfs);
        // Save the combined document
        merged.SaveAs("CombinedReports.pdf");
    }
}
using IronPdf;
using System.Collections.Generic;
using System.IO;
class Program
{
    static void Main()
    {
        // Create a list to store PDF documents
        var files = new List<PdfDocument>();
        // Get all PDF files from a directory
        string[] fileNames = Directory.GetFiles(@"C:\Reports\", "*.pdf");
        // Load each PDF file
        foreach (var fileName in fileNames)
        {
            files.Add(PdfDocument.FromFile(fileName));
        }
        // Merge all PDFs into one
        var merged = PdfDocument.Merge(pdfs);
        // Save the combined document
        merged.SaveAs("CombinedReports.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This sample code showcases a more dynamic approach to PDF merging. The code uses Directory.GetFiles() to automatically discover all PDF files in a specified folder, eliminating the need to hardcode individual file names. According to Microsoft's documentation on file operations, this method efficiently retrieves file paths matching your criteria.

Each discovered PDF file is loaded as a PdfDocument and added to a List collection. This approach scales efficiently whether you're merging three files or three hundred. The Merge() method accepts the entire list, processing all source documents in a single operation to create one new document. You can also make use of the int data type to track the index of each file as it's processed, if you wanted to.

The foreach loop provides a clean way to iterate through multiple PDF files, and you could easily add filtering logic here to select specific destination document files based on naming patterns, dates, or other criteria. This pattern works well for batch processing scenarios like monthly report compilation or document archival processes. For more advanced page manipulation options, explore the IronPDF page management features.

Get stated with IronPDF now.
green arrow pointer

How to Merge PDF Files from Different Sources?

Sometimes you need to combine PDF files from various sources - perhaps merging dynamically generated content with existing templates. IronPDF handles this seamlessly:

using IronPdf;
using System;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();
        // Create a PDF from HTML
        string html = @"<h1>Cover Page</h1>
                       <p>Example PDF From Multiple Sources</p>
                       <div style='page-break-after: always;'></div>";
        var coverPage = renderer.RenderHtmlAsPdf(html);
        // Load an existing PDF report
        var pdf = PdfDocument.FromFile(@"invoice.pdf");
        // Create a summary from URL
        var summary = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
        // Merge all three sources
        var finalDocument = PdfDocument.Merge(new[] { coverPage, pdf, summary });
        // Save the complete document
        finalDocument.SaveAs("MultipleSources.pdf");
    }
}
using IronPdf;
using System;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();
        // Create a PDF from HTML
        string html = @"<h1>Cover Page</h1>
                       <p>Example PDF From Multiple Sources</p>
                       <div style='page-break-after: always;'></div>";
        var coverPage = renderer.RenderHtmlAsPdf(html);
        // Load an existing PDF report
        var pdf = PdfDocument.FromFile(@"invoice.pdf");
        // Create a summary from URL
        var summary = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
        // Merge all three sources
        var finalDocument = PdfDocument.Merge(new[] { coverPage, pdf, summary });
        // Save the complete document
        finalDocument.SaveAs("MultipleSources.pdf");
    }
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

This advanced example demonstrates IronPDF's versatility in handling different PDF sources. The ChromePdfRenderer class enables HTML to PDF conversion, perfect for generating dynamic cover pages or formatted content from your application data. The renderer supports modern web standards as outlined in W3C specifications.

The RenderHtmlAsPdf() method converts HTML new strings directly to PDF, supporting full CSS styling and JavaScript. The length of the HTML string does not affect the conversion quality. The RenderUrlAsPdf() method fetches and converts web content, useful for incorporating live data or external resources. When dealing with web sources, an internal reader manages the stream data. You can learn more about these rendering options in the HTML to PDF tutorial.

By combining these rendering methods with existing PDF documents, you can create sophisticated document workflows. This approach works excellently for scenarios like adding branded cover pages to reports, appending legal disclaimers to contracts, or combining user-generated content with templates. The instance of the merged document maintains all formatting from each source file while creating a cohesive single PDF.

Output

In this screenshot image, we can see our PDF has been successfully created by merging multiple files together.

How to Merge PDF Files in .NET: Figure 3 - PDF merged from multiple sources

Conclusion

IronPDF transforms the complex task of merging PDF files in .NET into a straightforward process requiring minimal code. From simple two-file combinations to sophisticated multi-source document assembly, the library handles the technical complexity while providing an intuitive API. Whether you're working with a single file or processing large numbers of source documents, IronPDF maintains the integrity of your destination document throughout the merge process.

The examples in this tutorial demonstrate how easily you can integrate PDF merging capabilities into your .NET applications. Whether you're building document management systems, automating report generation, or processing user uploads, IronPDF provides the tools you need to combine PDF files efficiently and utilize various input sources.

Ready to implement PDF merging in your project? Start with a free trial that best fit your needs. Visit the comprehensive documentation for more advanced features like adding watermarks, applying security, splitting PDF documents, and troubleshooting tips for better exception handling.

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of ...Read More
Ready to Get Started?
Nuget Downloads 15,824,053 | Version: 2025.10 just released