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;

Planet PDF and ARTS PDF are both divisions of BinaryThing

Related Products at PDF Store

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

ARTS PDF Split & Merge Lite

The easiest way to split and merge PDFs! It provides a simpler method of splitting and merging your ... View full product details
Download free demo

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

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