Working with Bookmarks
jPDFAssemble and jPDFProcess allow to create new bookmarks or manipulate existing bookmarks in PDF documents.
Here is an example on how to add bookmarks for each page of a PDF document:
// Get current bookmark root Bookmark rootBK = pdfDoc.getRootBookmark(); // Create a root bookmark if it's null if(rootBK == null) { rootBK = pdfDoc.createRootBookmark(); } // Add a bookmark for each page for (int i = 1; i <= pdfDoc.getPageCount(); i++) { Bookmark bk = rootBK.addChildBookmark("Page" + " " + i); // add a go to page i action to the bookmark pdfDoc.addGoToPage(bk, i); } // Save the PDF document pdfDoc.saveDocument("doc1_bookmarks.pdf"); |
Download the full Java Program
https://www.qoppa.com/files/pdfassemble/guide/sourcesamples/SimpleCreateBookmarks.java