Acrobat Javascript – Bookmark Page Count?

Okay so I’m here trying to get myself acquainted with Adobe Acrobat’s Javascript API — I feel like I may be missing some easy ways of doing certain things, but let’s find that out together.

The Question:
How would I go about finding the amount of pages that belong to a bookmark?

For example, I have the following Bookmark layout:

Intro [3 pages]  
Factions [2 pages]  
Character [3 pages]  
End [1 page]  

(would have posted a picture, but I don’t have the permission to do so :/)

Essentially I would like to be able to automate the extraction of the # of pages each bookmark has, for a little project I’m working on to speed stuff up at work.

My code thus far:

/* Count Bookmark Children
    TODO: Count Pages of each Bookmark */

function CountBm(bm) {
    var count = 0;

    console.println("Bookmark name: " + bm.name);
    bm.execute(); // goto bm -- not necessary, just for personal reasons

    console.println("Bookmark Start Page: " + (this.pageNum+1));

    /* This would only work if each page in the bookmark was a child
       of the bookmark being checked */
    if (bm.children != null) {
        for (var i = 0; i < bm.children.length; i++)
            count++;
    }
    console.println("Pages in Bookmark: " + count);
}

var bkmk = bookmarkRoot.children[2]; // Character Bookmark
CountBm(bkmk);

Also, for the last two lines of that code, is there a better way to reference specific bookmarks? By name, perhaps?


Source: bookmarks

Leave a Reply