Merge PDF
In the following three examples, you merge PDF documents. The first example illustrates merging two documents in a single step, the second appending three documents in three steps, and the third adding output options that suppress included bookmarks in a merged PDF.
Watch the Video
How to Merge PDF
The following steps illustrates merging PDF documents and adding options when merging a document.
Steps for Merging a PDF Document
- Create a
MergeDocument
object using the staticMerge
method, passing the two PDFs to be merged. - 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
Append multiple PDFs by calling the Append
method. The following steps and sample code illustrates.
- Create a
MergeDocument
object and pass the first document to the constructor. - Call the
MergeDocument
instance'sAppend
method and pass the PDF to be merged. Repeat for all documents requiring merging. - Call the Document instance's
Draw
method to save the appended document.
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, the following sample code illustrates.
- Create a
MergeDocument
object and pass the first document to its constructor. - Create a
MergeOptions
object by calling theAppend
static property. - Set the
MergeOptions
Outlines method tofalse
. - Pass the
MergeOptions
object to theAppend
method. - Call the
MergeDocument
Append
method, passing in an additional PDF to be merged. - 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") ;
GitHub Project
Clone or view the example project at GitHub. This example code above is in the Examples/MergePDFs.cs file.
Getting Started
NuGet Package
DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is through the Visual Studio Package Manager, but you can also download from NuGet.
DynamicPDF Core Suite Information
More information on DynamicPDF Core Suite is available from its website.
Available on Other Platforms
DynamicPDF Core Suite is also available for Java and COM/ActiveX. Refer to the respective product pages for more details.
- Java - DynamicPDF Merger for Java
- COM/ActiveX - DynamicPDF Merger for COM/ActiveX