Outlines & Bookmarks
Developers can use the BookmarkManager
to add bookmarks to a PDF document. Access the BookmarkManager
by calling the getBookmarks
method on its PdfDocument.
BookmarkManager bookmarks = pdf.getBookmarks();
In the featured code example, we call the addBookmarkAtEnd
method to add four top-level bookmarks (one after another) to the working PdfDocument
before saving the modifications to the disk. Opening the modified PDF after executing the above code will show the bookmarks appearing in the order listed below:
- Author's Note
- Table of Content
- Summary
- References
The method addBookmarkAtStart
can prepend a bookmark, making it appears before other bookmarks if defined previously. For example, the line of code shown below, if it were placed right after Line 16 of the featured code example, would make the bookmark "Foreword" appear before the first item in the list presented previously.
bookmarks.addBookMarkAtStart("Foreword",1);
IronPDF has the ability to recognize bookmarks that have been added to the PDF using other third-party software. This gives the library considerable flexibility in terms of adding and modifying bookmarks in post-rendered PDF documents as required by the business.