Bookmark navigation

Q: I am interesting on the function of bookmark navigation. So could you please provide a sample that illustrate this function?
I added the following code after “PDFDoc doc = new PDFDoc(str);” in method onActivityResult() of PDFViewCtrlDemo.java:

Bookmark bm = doc.getFirstBookmark();
for (int i = 0;; i++){
Log.d(“TEST”, String.format("%s = %d", bm.getTitle(), bm.getAction().getDest().getPage().getIndex()));
bm = bm.getNext();
}

However, I get an error. Any pointers to help me with PDF bookmarks navigation ?

A:

To handle this I would suggest you to use the following approach, which checks whether the bookmark is valid or not:

Bookmark bm = doc.getFirstBookmark();
while (bm.isValid()) {
Log.d(“TEST”, String.format("%s = %d", bm.getTitle(), bm.getAction().getDest().getPage().getIndex()));
bm = bm.getNext();
}

Regarding the total number of bookmarks, you must traverse the bookmark tree to get that information. Please, take a look at our Bookmark sample at http://www.pdftron.com/pdfnet/samplecode/BookmarkTest.java.

Also, you can check these links for more information:
http://www.pdftron.com/pdfnet/Javadoc/pdftron/PDF/Bookmark.html