Skip to main content

Merge Options

Version: 12.0

Merge Options

When merging PDFs, often information such as JavaScript, a PDF's properties, metadata, form fields, and other content should be excluded from an existing PDF to be merged. Use the MergeOptions class to customize what is merged from an existing PDF.

MergeOptions​

The MergeOptions class customizes how documents are merged. The MergeOptions class has numerous properties that customize which content from a PDF is merged.

Properties​

PropertyDescription
AllGets a MergeOptions object with all options set to true.
AllOtherDataGets or sets a value indicating if all other document data should be imported.
AppendGets a MergeOptions object that you would typically use when appending documents.
DocumentInfoGets or sets a value indicating if document information should be imported.
DocumentJavaScriptGets or sets a value indicating if document level JavaScript should be imported.
DocumentPropertiesGets or sets a value indicating if document properties should be imported.
EmbeddedFilesGets or sets a value indicating if the Embedded files should be imported.
FormFieldsGets or sets a value indicating if form fields should be imported.
FormsXfaDataGets or sets a value indicating if form XFA data should be imported.
LogicalStructureGets or Sets the value indicating if logical structure should be imported.
NoneGets a MergeOptions object with all options set to false.
OpenActionGets or sets a value indicating if the documents opening action (initial page and zoom settings) should be imported.
OptionalContentInfoGets or sets the Output Content should be imported.
OutlinesGets or sets a value indicating if outlines and bookmarks should be imported.
OutputIntentGets or Sets a value indication if OutputIntent should be imported.
PageAnnotationsGets or sets a value indicating if annotations should be imported.
PageLabelsAndSectionsGets or sets a value indicating if page labels and sections should be imported.
RootFormFieldGets or sets the root form field for imported form fields.
RootOutlineGets or sets the root outline for imported outlines.
XmpMetadataGets or sets a value indicating if Xmp Metadata should be imported.

Using MergeOptions Statically​

To simplify merging, there are three defined static MergeOptions properties that do not require a user to specify numerous properties needlessly when merging.

By default, if a MergeDocument instance's constructor omits specifying MergeOptions, then it uses the MergeOptions.All as the merge options. When using a MergeDocument instance's Append method, if the method omits specifying merge options, then it uses MergeOptions.Append as the merge options.

important

MergeOptions do not apply to the PDF to be produced by the MergeDocument instance, only to the PDF documents being loaded/appended into the MergeDocument.

The following example illustrates using MergeOptions statically two different ways. First, it merges two documents together and specifies MergeOptions.None for both. Second, it creates a new MergeDocument instance and loads a PdfDocument and MergeOptions for that document. Then, it appends two PDF documents and specifies MergeOptions for those documents.

MergeDocument document = MergeDocument.Merge("DocumentB.pdf", MergeOptions.None, "outline-example.pdf", MergeOptions.None);
document.Draw(outputPath);

MergeDocument document1 = new MergeDocument("DocumentA.pdf", MergeOptions.None);
document1.Append("DocumentB.pdf", MergeOptions.None);
document1.Append("outline-example.pdf", MergeOptions.None);
document.Draw(outputPath);
Dim document As MergeDocument = MergeDocument.Merge("DocumentB.pdf", MergeOptions.None, "outline-example.pdf", MergeOptions.None)
document.Draw(outputPath)

Dim document As New MergeDocument("DocumentA.pdf", MergeOptions.None)
document.Append("DocumentB.pdf", MergeOptions.None)
document.Append("outline-example.pdf", MergeOptions.All)
document.Draw(outputPath)


[MergePdfExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/MergePdfExample.cs){#gitlink-id target=_blank}


[MergePdfExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/MergePdfExample.vb){#gitlink-id target=_blank}

^^^ MergeOptions Example Figure 1. Removing bookmarks, outline, tags, and attachment from merged PDFs. ^^^

Using MergeOptions​

You are not limited to using MergeOptions statically, you can also specify exactly which options to exclude. Instantiate a MergeOptions instance - rather than use one of its static methods - for complete control over the document parts that are merged into the final PDF.

The following example illustrates creating a MergeOptions instance and setting several of its properties to false so they exclude the specified elements.

MergeDocument document = new MergeDocument("DocumentA.pdf", MergeOptions.All);
MergeOptions options = new();
options.Outlines = false;
options.EmbeddedFiles = false;
options.LogicalStructure = false;
document.Append("DocumentB.pdf", options);
document.Append("outline-example.pdf");
document.Draw(outputPath);
Dim document As New MergeDocument("DocumentA.pdf", MergeOptions.All)
Dim options As New MergeOptions() With {
.Outlines = False,
.LogicalStructure = False,
.EmbeddedFiles = False
} document.Append("DocumentB.pdf", options)
document.Append("outline-example.pdf")
document.Draw(outputPath)

[MergePdfExample.cs](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-csharp-examples/Examples/MergePdfExample.cs){#gitlink-id target=_blank}


[MergePdfExample.vb](https://github.com/DynamicPDF/examples-dynamicpdf-core-suite-dotnet-core/blob/master/dynamicpdf-vbnet-examples/Examples/MergePdfExample.vb){#gitlink-id target=_blank}