Removing filename bookmarks created by Acrobat

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.

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(('.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

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

You May Also Like

About the Author: Sean Stewart

Leave a Reply