Examples

Merge PDF (.NET Core/Framework)

In the following three examples, you merge a PDF using C# .NET Core. The examples illustrate merging two documents in a single step, appending three documents in three steps, and adding output options that suppress including bookmarks in a merged PDF.

Watch the Video

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");
document.Draw("output.pdf");

Steps to Append PDF

You can append multiple PDFs by calling the Append method.

  1. Create a MergeDocument object passing in the first document.
  2. Call the MergeDocument Append method, passing in the PDFs 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 two documents to the MergeDocument object.

Sample Code - C#

MergeDocument document = new MergeDocument("DocumentA.pdf");
document.Append("DocumentB.pdf");
document.Append("DocumentC.pdf");
document.Draw("output.pdf");

Steps for Specifying MergeOptions for a PDF Document

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

  1. Create a MergeDocument object passing in the first document.
  2. Create a MergeOptions object by calling the Append static property.
  3. Set the MergeOptions Outlines method to false.
  4. Pass the MergeOptions object to the Append method.
  5. Call the MergeDocument Append method, passing in an additional PDF to be merged.
  6. Call the Draw method to save the appended document.

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#

MergeDocument document = new MergeDocument("DocumentA.pdf");
MergeOptions options = MergeOptions.Append;
options.Outlines = false;
document.Append("DocumentB.pdf", options);
document.Append("DocumentC.pdf");
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!