How to Add PDF Outlines and Bookmarks in Java

By ComPDFKit | 2023 Jul 14
Viewer Java

Whether your apps help create a lengthy report, a user manual, or an ebook, outlines and bookmarks can make it easy for your readers to navigate through your content and find the information they need rapidly. Hence, do you want to improve user satisfaction? Do you want your product to stand out from hundreds of competing products? Then, you must keep reading.


Outlines and bookmarks have the same aim to guide users to find what they want, but they also have differences. But if you have tried the outline and bookmark features, you may see there are some incompatible problems. We will explain all these parts, including their differences and the reason why incompatible problems exist.

Differences Between Outlines and Bookmarks


PDF outlines and bookmarks are navigation tools that allow users to quickly and easily jump to different parts of a PDF document. With these navigation tools, app makers could give a better reading experience to find key points without having to scroll through each page manually.


Outlines are hierarchical structures that provide a visual directory of the document's content, displaying the structure of the document to the user. Outlines can have parent and child outlines, allowing for a relatively detailed view of the entire document content.


However, bookmarks are more personalized navigation tools that allow users to mark specific points in the document and quickly jump to them. Bookmarks can be created by the user based on their preferences and habits. It makes them a convenient way to navigate through lengthy documents.


Now, you can learn that an outline is useful for a preliminary understanding of the full text or for searching the structure of an article, but bookmarks are useful for marking specific points in personal articles.



Technical Incompatibility Among Manufacturers


Outlines are included in the Adobe PDF specification. But when it comes to content not documented in the PDF specification, such as bookmarks, different providers of PDF technology may create different interpretations and ways of processing them. 


It means that each PDF software vendor can decide how to implement bookmark support. This results in different UI appearances and methods to create bookmarks. For example, a PDF with bookmarks that were created in PDF Reader Pro may disappear when opening in Adobe Acrobat Reader.



Add Outlines & Bookmarks in Java


ComPDFKit handles outlines and bookmarks differently and separately. And due to the common problem in PDF processing, ComPDFKit is incompatible with other PDF manufacturers. But ComPDFKit could provide the all-in-one PDF solution, you can achieve all PDF processing by purchasing the technologies of ComPDFKit. Keep reading to learn how to add outlines and bookmarks with ComPDFKit in Java.




ComPDFKit has a Java library that provides an easy-to-use interface for working with PDF documents, including adding outlines. We will show you a code example to create a new parent outline with the title “Chapter 1”, and add child outline “1.1” to the parent outline.


CPDFOutline pdfOutlineRoot = cpdfDocument.getOutlineRoot();
CPDFOutline fistOutline = pdfOutlineRoot.insertChildAtIndex(0);
fistOutline.setTitle("Chapter 1");
CPDFOutline subOutline = fistOutline.insertChildAtIndex(0);




Here is an example of how to add bookmarks using ComPDFKit with Java language. It shows the methods to set page 8 as a bookmark.


CPDFBookmark bookmark = new CPDFBookmark(8, "bookmark_text", "" + System.currentTimeMillis());
   boolean res = cpdfDocument.addBookmark(bookmark);



Outline and bookmark may seem similar at first glance. It's a common situation that many manufacturers provide incompatible technologies to handle bookmarks. To avoid the incompatibility, it’s wise to choose an all-in-one PDF SDK. More details of how ComPDFKit handles outlines and bookmarks can be referred to here. You can also contact us for a free trial.