Need to merge two documents and keep original bookmarks

How can I merge Document1 and Document2 to produce the Merged document? Concatenating the files leaves all of the bookmarks on the same level. I tried adapting the code in this post but I’m still doing something wrong (

Document1.pdf (505.5 KB)
Document2.pdf (727.3 KB)
Merged.pdf (1.3 MB)


Can you please share the code snippet that you are using to merge the PDF files at your end? Also, please share how you have generated the expected output PDF that you have shared with us? Is it using some other API or you have created it manually?

I figured it out, just needed a couple of tweaks. Originally, the output doc was created using activePDF. We’re replacing it everywhere with Aspose.

var firstPdf = new Document("Document1.pdf");
var secondPdf = new Document("Document2.pdf");
var originalPageCount = firstPdf.Pages.Count;


var parentOutline = new OutlineItemCollection(firstPdf.Outlines)
	Title = "Title",
	Action = new GoToAction(firstPdf.Pages[originalPageCount + 1])

var bookmarkEditor = new PdfBookmarkEditor(secondPdf);
foreach (var bookmark in bookmarkEditor.ExtractBookmarks())
	var childOutline = new OutlineItemCollection(firstPdf.Outlines)
		Title = bookmark.Title,
		Action = new GoToAction(firstPdf.Pages[originalPageCount + bookmark.PageNumber])




It is nice to know that your issue has been resolved. Please keep using our API and feel free to create a new topic in case you face any issues.