How to Merge PDFs with Bookmarks and Metadata in C#
In legal, compliance, and archival workflows, keeping document navigation and metadata intact is critical. The Aspose.PDF.Plugin Merger for .NET lets you combine multiple PDFs, preserving original bookmarks and metadata—or creating new ones programmatically.
Handling Bookmarks When Merging
- Preserve Bookmarks: By default, MergeOptions can keep original bookmarks from all input files, providing seamless navigation in the merged PDF.
- Generate New Bookmarks: Create new bookmarks programmatically based on merged file names, sections, or TOC structures.
using Aspose.Pdf.Plugins;
var merger = new Merger();
var mergeOptions = new MergeOptions
{
KeepBookmarks = true // Ensures all input bookmarks are retained
};
mergeOptions.AddInput(new FileDataSource(@"C:\Docs\contract1.pdf"));
mergeOptions.AddInput(new FileDataSource(@"C:\Docs\contract2.pdf"));
mergeOptions.AddOutput(new FileDataSource(@"C:\Docs\merged_contracts.pdf"));
merger.Process(mergeOptions);Managing Document Metadata
- Preserve Original Metadata: By default, the metadata from the first PDF is retained in the output file.
- Add or Edit Metadata: Set
mergeOptions.Metadatato specify or override properties such as Title, Author, Subject, and Keywords.
mergeOptions.Metadata = new PdfMetadata
{
Author = "Compliance Team",
Title = "Merged Case File",
Subject = "2025 Contract Archive",
Keywords = "contracts, archive, legal"
};Complete Sample Code
using Aspose.Pdf.Plugins;
var merger = new Merger();
var options = new MergeOptions
{
KeepBookmarks = true,
Metadata = new PdfMetadata
{
Author = "Legal Team",
Title = "Complete Dossier",
Subject = "Case Archive",
Keywords = "archive, legal, contracts"
}
};
options.AddInput(new FileDataSource(@"C:\Cases\part1.pdf"));
options.AddInput(new FileDataSource(@"C:\Cases\part2.pdf"));
options.AddOutput(new FileDataSource(@"C:\Cases\complete_dossier.pdf"));
merger.Process(options);Use Cases
- Compliance archiving: Retain navigation and details for audits
- Legal bundles: Merge filings with preserved bookmarks for court
- Digital libraries: Combine reference works, keeping TOCs and metadata for search
Frequently Asked Questions
Q: Will original bookmarks be kept when merging?
A: Yes, set KeepBookmarks = true in MergeOptions to preserve all navigation aids.
Q: How do I add or override custom metadata?
A: Use the Metadata property on MergeOptions to set Title, Author, Subject, or Keywords as needed.
Q: Can I generate a new bookmark structure instead? A: Yes, you can programmatically create bookmarks, or use the TOC Generator for more advanced navigation.
Pro Tip: Combine merging with TOC generation for the ultimate navigation experience in archival and legal PDFs.