Tips & Tricks

Removing filename bookmarks created by Acrobat

December 21, 2004

Advertisement
Advertisement
 

With the release of Acrobat 6 came the ability to create a composite (binder) document from multiple files, (i.e. File > Create PDF > From Multiple Files.) When this is done, Acrobat automatically inserts a new top level bookmark at the start of each new file. The bookmark title will correspond to the source filename of the source file. While this level of separation can be helpful, it is counterproductive when the user wants the bookmark tree in the merged document to be continuous.

Here's a sample JavaScript to remove the top level bookmarks from the bookmark tree. This script will look for a ".pdf" extension to decide whether to remove the bookmark.

Note: Although I originally wrote this to be executed via a custom tool button using ARTS PDF Aerialist, you can also execute it from Acrobat Professional's JavaScript debugger.

/* 
Author: Sean Stewart, ARTS PDF
Date: 2 June 2004
Description: When you merge documents using Acrobat's merge process
it creates a high-level bookmark with the filename of the merged document and
subordinates all bookmarks from the merged document below this.

This script can be used to:
1) moves all subordinated bookmarks up the bookmark tree; and
2) delete the filename bookmark
*/

var bm = this.bookmarkRoot;

// Find the bookmarks which have .PDF and move all their children to the end
// of the bookmark tree. Add each found bookmark to an array so that
// it can be deleted at the conclusion of the process

// Create an array to hold the bookmarks to delete @ a later stage
var bmToDeleteArray = new Array();

// Iterate through each bookmark
var ibmLength = bm.children.length;
for (var i = 0; i < ibmLength; i++)
{
    // Check to see if this is a filename which
    // contains sub-ordinate bookmarks
    var bmToCheck = bm.children[i];

    if((bmToCheck.name.indexOf(".pdf")!=-1) && (bmToCheck.children!=null))
    {
        console.println("found bookmark with children " + i);
        
        // Move all children to the end of the root bookmark tree
        // being sure to move the first item in each case
        // note: this is because the queue is shrinking as
        // we move each item

        var ibmChildrenToMoveLength = bmToCheck.children.length;
        for(var j=0; j<ibmChildrenToMoveLength; j++)
        {
           console.println("moving bookmark " + j);

           bm.insertChild(bmToCheck.children[0], bm.children.length);
        }

        // Add this to the array of bookmarks to be deleted later
        bmToDeleteArray[bmToDeleteArray.length] = bmToCheck;
    }			
}

// Iterate through the array of 'filename' bookmarks to delete
// and delete them

for (var i = 0; i < bmToDeleteArray.length; i++)
{
// Delete bookmark
   bmToDeleteArray[i].remove();
}

// Finally remove the array as a nicety
delete bmToDeleteArray;

(ARTS PDF and Planet PDF have been since acquired by Debenu)

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.