iText

Merging documents with bookmarks

This example was originally written in answer to the question How to merge PDFs and add bookmarks? for iText 5.

The code here is a direct port from the iText 5 code. Merging documents while maintaining bookmarks in iText 7 and later versions is done automatically when using the PdfMerger (Java/.NET) class.

insertandadaptoutlines

##GITHUB:https://github.com/itext/itext-publications-examples-java/blob/master/src/main/java/com/itextpdf/samples/sandbox/merge/InsertAndAdaptOutlines.java##

##GITHUB:https://github.com/itext/i7ns-samples/blob/master/itext/itext.samples/itext/samples/sandbox/merge/InsertAndAdaptOutlines.cs##

mergewithoutlines

##GITHUB:https://github.com/itext/itext-publications-examples-java/blob/master/src/main/java/com/itextpdf/samples/sandbox/merge/MergeWithOutlines.java##

##GITHUB:https://github.com/itext/i7ns-samples/blob/master/itext/itext.samples/itext/samples/sandbox/merge/MergeWithOutlines.cs##

Resources

bookmarks.pdf
hello.pdf
links1.pdf
links2.pdf

Results

cmp_insert_and_adapt_outlines.pdf

cmp_merge_with_outlines.pdf