Tips & Tricks

Updating PDF Bookmarks Quickly

July 25, 2003

Advertisement
Advertisement
 

In another last bookmark-related tip we showed you how to change the properties for bookmarks one by one. This can be somewhat impractical when you have hundreds or thousands of bookmarks.

If we use a little bit of JavaScript we can whizz round all the bookmarks in your PDF (or PDF's) and set the properties for all the bookmarks in your documents.

  1. Select 'Document Javascripts...' from 'Tools>Javascript' menu.
  2. Type a name for the script (anything you can remember) in the script name text area.
  3. Click 'Add', then Click 'Edit'
  4. Copy the javascript code below into the Edit Window.
    
function ChangeBookmarkColors(bm, nLevel)
{
   // !!!!! Change 3: Add Conditional Options under this line 
   var s = "";
   for (var i = 0; i < nLevel; i++)
     s += " ";

   // !!!!! Change 1: This line here with other options.
   bm.color = ["RGB",0,0,1];

   if (bm.children != null)
   for (var i = 0; i < bm.children.length; i++)
      ChangeBookmarkColors(bm.children[i], nLevel + 1);
}

// Start the Program
// !!!!! Change 2: this.bookmarkRoot to alternative
ChangeBookmarkColors(this.bookmarkRoot, 0);

When you click the OK button you will be taken back to this screen. If you now choose the Close button Acrobat will activate the selected Javascript on the active document.

You should find all of you bookmarks have been colored blue. (["RGB",0,0,1]).

OPTIONS

Instead of just changing the color, try replacing (or adding to) the line indicated with the exclamation marks:

  • To Set Styles:
    • bm.style = bkmrkStyle;
        Where bkmrkStyle is one of the following values:
      • 0 = Plain,
      • 1 = Italic,
      • 2 = Bold and
      • 3 = Bold&Italic
      • For example to get a blue, bold&italic bookmark:
bm.style = 3;
bm.color = ["RGB",0,0,1]

Use a differerent Color Model ("CYMK", "G")

  • Instead of using the Red, Green and Blue color model we can use the Cyan, Magenta, Yellow and Black color model
bm.color = ["CYMK",0,1,1,0] 

Start at a Different Bookmark

  • If you don't want to apply your style changes to all of the bookmarks, then change the 'this.bookmarkRoot' at the line indicated (Change 2) to one of the following:
    • this.bookmarkRoot.children[0].children[xxx]; where xxx is the bookmark index number in the tree (see console output for the index number in [] square brackets. Example:
this.bookmarkRoot.children[0].children[1];
  • The above line would change the second bookmark (the first bookmark is index 0, not index 1) and all of it's children (if it had any).

Use a Condition

  • At Change postion 3, use a condition to test if the bookmark should be styled or not, for example check the name of the bookmark or check if it has any child bookmarks:
if(bm.name.indexOf("Acrobat") == -1) return; 

Copyright Dave Wraight & Planet PDF. No unauthorised reproduction, distribution or publication permitted.

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.