Merge PDF (.NET Core/Framework)

In the following three examples, you merge a PDF using C#. The examples illustrate merging two documents in a single step, appending three documents in three steps, and appending a document while limiting the appended document to two pages.

How to Merge PDF

Download the NuGet package and Github project to get started. The following steps illustrates merging PDF documents and adding options when merging a document.

Steps for Merging a PDF Document

  1. Create a MergeDocument object using the static Merge method, passing in two PDFs to be merged.
  2. Call the Draw method to save the merged PDF.

Sample Code - C#

MergeDocument document = MergeDocument.Merge("DocumentA.pdf", "DocumentB.pdf");

Steps to Append PDF

You can append multiple PDFs by calling the Append method.

  1. Create a MergeDocument object .
  2. Call the MergeDocument Append method, passing in the PDF to be merged.
  3. Call the Draw method to save the appended document.

You can call the Append method multiple times. For example, in the following code you append three documents to the MergeDocument object.

Sample Code - C#

MergeDocument document = new MergeDocument();

Steps for Specifying MergeOptions for a PDF Document

You can specify different options while appending a document using the MergeOptions class.

  1. Create a MergeOptions object by calling the Append method.
  2. Set the MergeOptions Outlines method to false.
  3. Pass the MergeOptions object to the Append method.

This example is admittedly simplified. In this example you specify that Outlines does not import a PDF's outlines or bookmarks. Other examples include FormsXfaData, OutputIntent, and other possible options. For more information, refer to the MergeOptions class referenced above.

Sample Code - C#

MergeOptions options = MergeOptions.Append;
options.Outlines = false;
document.Append("DocumentC.pdf, options);
document.Draw("output.pdf") ;

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

GitHub Example Project

Clone or view the example project at GitHub. This example is is the Examples/MergePDFs.cs file.

Clone or View Example Project on GitHub

DynamicPDF Merger Information

More information on DynamicPDF Merger can be found here:

Java and COM/ActiveX Platforms

The DynamicPDF Merger is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!