Users complained that the merged pdfs produced did not have Inherit Zoom turned on so I modified the code like so:
var mergedPdf = new Document();
foreach (var file in Directory.GetFiles(@“c:\temp”, “*.pdf”))
{
var pdf = new Document(file);
mergedPdf.Pages.Add(pdf.Pages);var outline = new OutlineItemCollection(mergedPdf.Outlines) { Title = Path.GetFileNameWithoutExtension(file) };
//outline.Destination = new GoToAction(mergedPdf.Pages[pageCount]);
outline.Destination = new XYZExplicitDestination(pageCount, 0, mergedPdf.Pages[pageCount].MediaBox.Height, 0);
mergedPdf.Outlines.Add(outline);pageCount += pdf.Pages.Count;
}var docInfo = mergedPdf.Info;
docInfo.Title = “Title”;
docInfo.Author = “Company”;mergedPdf.Form.Flatten();
var editor = new PdfContentEditor(mergedPdf);
editor.ChangeViewerPreference(ViewerPreference.HideMenubar);
editor.ChangeViewerPreference(ViewerPreference.PageModeUseOutlines);editor.Save(@“c:\temp\Merged.pdf”);
That fixed the issue. However, now when the resulting pdf is saved as another filename, reduced, or optimized in Adobe Reader, the bookmarks are either broken or removed altogether.
Save As → new file: bookmarks remain but are broken
Save As → Reduced/Optimized PDF: bookmarks are removed
Here’s a link to samples of each case: Samples.zip