title: Acrobat Javascript - Bookmark Page Count?
body: <p>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.</p>
  
  <p><strong>The Question:</strong>
  How would I go about finding the amount of pages that belong to a bookmark?</p>
  
  <p>For example, I have the following Bookmark layout:</p>
  
  <pre><code>Intro [3 pages]  
  Factions [2 pages]  
  Character [3 pages]  
  End [1 page]  
  </code></pre>
  
  <p>(would have posted a picture, but I don't have the permission to do so :/)  </p>
  
  <p>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.</p>
  
  <p><strong>My code thus far:</strong></p>
  
  <pre><code>/* 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 &lt; bm.children.length; i++)
              count++;
      }
      console.println("Pages in Bookmark: " + count);
  }
  
  var bkmk = bookmarkRoot.children[2]; // Character Bookmark
  CountBm(bkmk);
  </code></pre>
  
  <p>Also, for the last two lines of that code, is there a better way to reference specific bookmarks? By name, perhaps?</p>