To delete all bookmarks in a PDF document, simply create a new empty root bookmark.
With jPDFProcess, use PDFDocument.createRootBookmark();
With jPDFAssemble, use PDFAssemble.createRootBookmark();
With jPDFEditor, use PDFEditorBean.getDocument().createRootBookmark();
Here is sample code to do so:
// Load the document PDFDocument pdfDoc = new PDFDocument ("input.pdf", null); // Get the root bookmark, create one if necessary Bookmark rootBK = pdfDoc.getRootBookmark(); // if there is a rootbookmark, make sure it's empty if (rootBK != null) { rootBK = pdfDoc.createRootBookmark (); } |
With jPDFNotes, it is possible to delete the bookmarks by removing all children in the root bookmark:
int count = 0; // We can leave "outlines" entry in root dictionary, but should remove all bookmarks Bookmark root = mPDFDocument.getRootBookmark(); if (root != null) { int childCount = root.getChildCount(); for (int i = 0; i < childCount; i++) { // remove these in reverse order since it could alter the array try { root.removeChildBookmark(childCount - 1 - i); } catch (PDFException e) { e.printStackTrace(); } } } |