Skip to main content
justinm39103228
New Participant
April 19, 2016
Question

Batch Sequence - Renaming Bookmarks

  • April 19, 2016
  • 2 replies
  • 7656 views

Hi,

Complete JS noob here. Whenever I have an issue I just google scripts and copy and paste them and adjust them accordingly - I have never written one on my own.

So if anyone is feeling nice enough to write an entire script that I can just copy and paste (and tweak) for this, THANK YOU!

So what I want to do is to automate the sequential renaming of bookmarks. I have created a PDF consisting of other PDFs and have used the built-in Acrobat features to automatically create bookmarks. Instead of having to manually rename all these bookmarks, is there a script out there that can do this? I need to make the bookmarks sequential, for example:

TAB 1

TAB 2

TAB 3

TAB 4

The bookmarks are already in the right spots, all I need to do is rename them similarly to the naming convention used in this example.

2 replies

New Participant
July 5, 2018

This is such a good question. Have you found the answer ?

BarlaeDC
Community Expert
Community Expert
July 5, 2018

Hi,

 

It is pretty simple to do this, the documentation pretty much gives you all the code, but here you go

 

 

var myBookMarks = this.bookmarkRoot;

for ( var i = 0; i < myBookMarks.children.length; i++)

{

    myBookMarks.children[i].name = "Tab" + i;

}

 

Just add this to a button and you are good to go, you could even make it a application level script but you would need to change line 1 as the this object wouldn't point to a document.

 

Hope this helps

 

Malcolm

descentfan1975
Participating Frequently
September 28, 2022

Change the first line of code to this:

 

var myBookMarks = this.bookmarkRoot.children[0];

 

This code change makes the root bookmark for interation to the first of the top level bookmarks.

A more generic solution could be implemented by searching the top level bookmarks for the "Sheets and Views" title. 

 

 


That worked perfect! Thanks so much.

 

Last question...I've put the Action into a button on the toolbar. When I click it, a prompt opens on the right to select files. Is there a way to have the action just run on the current open file or will it always prompt me for the file?

Inspiring
April 19, 2016

When I have combined PDFs I always get an additional bookmark with the source PDF's name. How do you want to handle this bookmark?

It is possible to remove these bookmarks with JavaScript.

http://www.planetpdf.com/developer/article.asp?ContentID=RemovingfilenamebookmarkscreatedbyAcrobat&gid=6881

Removing filename bookmarks created by Acrobat

The script puts all the bookmarks into an array and only adds bookmarks that do  not have a file name ending in ".pdf". You could rename the bookmark as part of the process adding the bookmark to the array.