We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Expand bookmark to show child bookmarks in PDF file

Using the Aspose.PDF for Java (aspose-pdf-9.5.2-jdk16.jar), how can I create a bookmark so that it will already be expanded to show child bookmarks when the PDF file is opened in Adobe Reader and the bookmark view is opened? See sample code below. It creates all the bookmarks, but when the Bookmark view is opened, the "Document Bookmarks" is not expanded by default. Thanks

Bookmark topLevelBookmark = new Bookmark();
topLevelBookmark.setTitle("Document Bookmarks");
topLevelBookmark.setOpen(true);
topLevelBookmark.setPageNumber(1);

Bookmarks docBookmarks = new Bookmarks();

Bookmark docBookmark = new Bookmark();
docBookmark.setTitle(“Sub Bookmark 1”);
docBookmark.setOpen(true);
docBookmark.setPageNumber(1);
docBookmarks.add(docBookmark);

docBookmark = new Bookmark();
docBookmark.setTitle(“Sub Bookmark 2”);
docBookmark.setOpen(true);
docBookmark.setPageNumber(2);
docBookmarks.add(docBookmark);

topLevelBookmark.setChildItems(docBookmarks);

PdfBookmarkEditor pdfBookmarkEditor = new PdfBookmarkEditor();
pdfBookmarkEditor.bindPdf(combinedDocsPdfFileLocation);
pdfBookmarkEditor.deleteBookmarks();
pdfBookmarkEditor.createBookmarks(topLevelBookmark);
pdfBookmarkEditor.save(combinedDocsPdfFileLocation);
pdfBookmarkEditor.close();
</pre

Hi Simon,


Thanks for your inquiry. You need to set PageMode for setting PDF document preview, UseOutLines enum value is used for bookmark view. Please check sample code snippet for the purpose. You may save your document in stream and pass to Document object to set its preview preference.

Document doc = new Document(“input.pdf”);<o:p></o:p>

//i.e. show thumbnails, full-screen, show attachment panel

doc.setPageMode(PageMode.UseOutlines);

for (OutlineItemCollection item : (Iterable) doc.getOutlines())

{

item.setOpen(true);

}

doc.save("output.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

So there is no support to accomplish this via the PdfBookmarkEditor? I need to load the PDF in the Document?

Hi Simon,


The requirement cannot be accomplished using com.aspose.pdf.facades package but as shared by Tilal, it can be accomplished with latest Document Object Model (DOM) of com.aspose.pdf package and all the enhancements and bug fixes will be made in com.aspose.pdf package.