import com.aspose.pdf.Document; import com.aspose.pdf.License; import com.aspose.pdf.OutlineItemCollection; public class HowToReadBookmarksInPdfUsingJava { public static void main() throws Exception { //main() function for HowToReadBookmarksInPdfUsingJava // Instantiate Aspose.PDF license to remove trial version limitations while fetching bookmarks in PDF License BookmarksPDFlicense = new License(); BookmarksPDFlicense.setLicense("Aspose.PDF.lic"); // Load the target PDF file to read the bookmarks Document samplePDFWithBookmarks = new Document("PDFWithBookmarks.pdf"); // Iterate through all the bookmarks and fetch the bookmark text and formatting information for (OutlineItemCollection Bookmark : (Iterable<OutlineItemCollection>) samplePDFWithBookmarks.getOutlines()) { System.out.println("Title :- " + Bookmark.getTitle()); System.out.println("Is Italic :- " + Bookmark.getItalic()); System.out.println("Is Bold :- " + Bookmark.getBold()); System.out.println("Color :- " + Bookmark.getColor()); // Check if there is any child bookmarks if(Bookmark.size() > 0) { System.out.println("Reading Child bookmarks..."); // Iterate through each bookmark to fetch child bookmark properties for (OutlineItemCollection childBookmark : (Iterable<OutlineItemCollection>) Bookmark) { System.out.println("Title :- " + childBookmark.getTitle()); System.out.println("Is Italic :- " + childBookmark.getItalic()); System.out.println("Is Bold :- " + childBookmark.getBold()); System.out.println("Color :- " + childBookmark.getColor()); } } } } }