When merging PDFs together using DynamicPDF Merger or Core Suite, all bookmarks (or outlines) will be added to the output PDF by default. They will appear in the order they are merged, with the first document's bookmarks coming first, followed by the next document's bookmarks. However, this is not always the desired behavior, so let's take a look at a couple of other options.
Adding a Bookmark For Each Document
Sometimes you may want to add a bookmark for each document, but remove any of the bookmarks that are in the original PDFs. Accomplishing this can easily be done by adding a bookmark for each document and setting the Outlines merge option to false:
MergeDocument document = new MergeDocument();
MergeOptions mergeOptions = MergeOptions.Append;
mergeOptions.Outlines = false;
document.Outlines.Add("Bookmark for PDF", new XYDestination(document.Pages.Count + 1, 0, 0));
document.Append(fileName, mergeOptions);
The full example file is available here.
Organizing Bookmarks For Each Document
Other times you may want to add a bookmark for each document and place the original document's bookmarks as children. This can quickly be done by creating a bookmark for each document and setting the RootOutline merge option property to that bookmark:
MergeDocument document = new MergeDocument();
MergeOptions mergeOptions = MergeOptions.Append;
Outline outline = document.Outlines.Add("Parent Bookmark for PDF",
new XYDestination(document.Pages.Count + 1, 0, 0));
mergeOptions.RootOutline = outline;
document.Append(fileName, mergeOptions);
The full example file is available here.
Wrap Up
A C# Visual Studio project demonstrating this is available on GitHub:
https://github.com/DynamicPDF/dotnet-merge-pdf-bookmarks
There are of course many other options for how you may want to deal with bookmarks as well. If you have any questions or comments, I would love to hear from you.