This short tutorial describes how to read bookmarks in PDF using Java which is used to find some content quickly. With the help of this tutorial, you can not only retrieve bookmarks in PDF using Java but also fetch the child bookmarks of any other bookmark. You will also learn to display different properties of the bookmark like its title and formatting information like color, is bold, and is italic.
Steps to Read Bookmarks in PDF using Java
- Install Aspose.PDF from the Maven repository to read the bookmarks in PDF
- Load the target PDF file using the Document class object to fetch the bookmarks
- Iterate through all the bookmarks collection using OutlineItemCollection
- For each entry in the collection, display bookmark properties
- Iterate through each individual bookmark to access the child bookmarks in it
- Display each child bookmark properties
In this quick step-by-step procedure, we first load the target PDF file and then get the reference to its bookmarks collection to extract bookmarks in pdf using Java. We can also get access to the child bookmarks in each bookmark.
Code to Fetch Bookmarks in PDF using Java
This sample code demonstrates the process to fetch bookmarks in PDF using Java by loading the target PDF file from the disc. Then it gets access to its bookmarks list using the iterable interface implementation for OutlineItemCollection. This same collection of outline items can be used to get the child bookmarks from each bookmark.
In this tutorial, we learned how to read bookmarks in PDF using Java without installing any other third-party tool. If you want to perform the same process in some other language like C-Sharp, refer to the article on How to Read Bookmarks in PDF using C#.