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.

Related Products at PDF Store

ARTS PDF Aerialist

Take Acrobat to the next level with advanced splitting and merging; flexible bookmark creation and m... View full product details
Download free demo

PitStop Professional

The industry standard that combines preflight, interactive editing and automated correction capabili... View full product details
Download free demo

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99, Nitro PDF Pro is the m... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: PDF eBooks-Library

If you are looking for a good store of PDF content, you could do a lot worse than visiting eBooks-Library.com...

September 03, 2009
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit