Avatar of SharonBernal
 asked on

Delete child bookmarks in Acrobat Professional 8 Document

I have a rather large pdf made up of several files. The parent bookmark needs to be retained, however I have been tasked with removing all of the child bookmarks.

I have had a hard time finding javascript to allow me to do this, please help. The pdf that I have created has 6500 pages, deleting the child bookmarks manually would be quite a task.
Page Layout SoftwareAdobe AcrobatJavaScript

Avatar of undefined
Last Comment

8/22/2022 - Mon

I found this code but it fails at line 41 with an error "missing ; after for loop condition". The problem is that the ; is there.

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("delete me")!=-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 {
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;

Karl Heinz Kremer

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

I found a utlity for sale that almost does what I  need.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes