PDF In-Depth

Plug-in - Developing a plug-in to count all bookmarks

May 27, 2000

Advertisement
Advertisement
 

OK - this is a simple plug-in example to count all the bookmarks in the active document.

Basically it grabs the root bookmark and recurses through each child bookmark in-order. As it finds bookmarks it counts them. When all bookmarks have been counted a message is displayed to the user informing them of the count. Pretty simple... the recursion function was taken from page 49 of the SDK tutorial.

Here's the actual working code... everything else is part of the framework.


/*/////////////////////////////////////////////////////////////*/

/*/////////////////////////////////////////////////////////////*/

/* Recursively go through bookmark tree to visit each bookmark */

/*/////////////////////////////////////////////////////////////*/

/*/////////////////////////////////////////////////////////////*/

void CountAllBookmarks(PDBookmark ABookmark, int *pBookmarkCount)
{

        PDBookmark TreeBookmark;

   DURING

   if (!PDBookmarkIsValid (ABookmark))

   {

      E_RTRN_VOID

   }


   /* Let's count this bookmark */

   (*pBookmarkCount)++;

   /* Now visit that bookmark's children if it has any children */

   if (PDBookmarkHasChildren (ABookmark))

   {

      /* Get the first child of the bookmark */

      TreeBookmark = PDBookmarkGetFirstChild (ABookmark);

      while (PDBookmarkIsValid (TreeBookmark))

      {

         CountAllBookmarks (TreeBookmark, pBookmarkCount);

         TreeBookmark = PDBookmarkGetNext (TreeBookmark);

      }

   }

   HANDLER

      AVAlertNote("There has been a problem, sorry - you may want 
to add some error handling to VistAllBookmarks");

   END_HANDLER

}

/* Let's count those bookmarks */

static ACCB1 void ACCB2 BookmarkCountCommand(void *data)

{

   AVDoc avActive = NULL;

   PDDoc pdActive = NULL;

   PDBookmark bmRoot = {0,0};

   int iBookmarkCount = 0;

   char pszBookmarkCount[256] = {'\0'};


/* Get the active document as an AVDoc */

   avActive = AVAppGetActiveDoc();

   if (!avActive)

   {

   /* Who knows why we got here --- let's leave now before

      we get into trouble */

      return;

   }

   /* And glean a PDDoc from it */

   pdActive = AVDocGetPDDoc(avActive);

   if (!pdActive)

   {

   /* Hmmm, once again, we'd better exit the scene quickly... */

      return;

   }


/* ok - time for action */

   DURING

   /* Grab the root bookmark */


      bmRoot = PDDocGetBookmarkRoot (pdActive);

   /* Start counting... */

      CountAllBookmarks (bmRoot, &iBookmarkCount);

   HANDLER

   /* Damn - now what? */

      AVAlertNote("There has been a problem, sorry - you may want 
to add some error handling to BookmarkCountCommand");

      E_RTRN_VOID

   END_HANDLER

/* We need to subtract 1 from our Bookmark count as the Root bookmark 

   is not actually visible */

   iBookmarkCount--;

/* Display a message regarding the number of bookmarks */

   sprintf(pszBookmarkCount, "There are %d bookmarks in this document", 
iBookmarkCount);

   AVAlertNote(pszBookmarkCount);

/* We're done - let's get out of here */

}
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.