• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Batch Sequence - Renaming Bookmarks

New Here ,
Apr 18, 2016 Apr 18, 2016

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

2.3K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2016 Apr 19, 2016

Copy link to clipboard

Copied

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&g...

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 05, 2018 Jul 05, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

I know this is an old question, but I have a similar issue. I want to strip out parts of all the bookmarks. See the attached file....I want to remove the "22115-Safeway Manning CFS SHOP PLANS-" from every bookmark and just keep the S101, S201, etc.

Chris21784797mf9q_0-1663897374051.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

Hi,

 

similar to above:

var myBookMarks = this.bookmarkRoot;
for ( var i = 0; i < myBookMarks.children.length; i++)
{
    var lastDash = myBookMarks.children[i].name.lastIndexOf("-");
    myBookMarks.children[i].name = myBookMarks.children[i].name.substring(++lastDash, myBookMarks.children[i].name.length);
}

 

Run it from a button of the JavaScript console or an action.

 

To run from the console:

Open the console

Paste the code in

Select all the code

Press the keypad enter

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

So I tried creating a New Action using Acrobat Pro DC. Pasted in the code you gave me under "Execute Javascript" and it didn't do anything. It could be I don't know what I'm doing. Can you give me step-by-step instructions on how to add this?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Ok I think I found the problem but I don't know enough about Javascript to know how to fix it. When AutoCAD creates the bookmarks in the PDF, it creates a subheading called "Sheets and Views"

Chris21784797mf9q_0-1664323224476.png

The code doesn't seem to be able to go into child bookmarks. When I create a top level bookmark withouth the "Sheets and Views" subheading, the code works perfectly. How do I get it to go into the subheading bookmark?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

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. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

How exactly did you put this code into a toolbar button?  Did you use the "Action Wizard"?

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

Yeah I used the Action Wizard to create a "New Action" then added that action to a toolbar button by Customising the Quick Tools.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

The "Actions Wizard" is used to create batch processes that apply the same "Action" to several documents.  If you want a tool that just operates on the current document then you have two choices.

1) Create an automation tool that adds a toolbar button or menu item to the Acrobat UI

https://www.pdfscripting.com/public/Automating-Acrobat.cfm

 

2) Put your code in a "Custom Command", which you'll also find on the "Action Wizard" toolbar. 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 28, 2022 Sep 28, 2022

Copy link to clipboard

Copied

The Custom Command worked perfectly! Thank you so much for all your help!

 

Chris

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

Ok I'm back 🙂

 

The custom command has been working perfectly, but I've noticed one other little quirk in Acrobat. The page labels that you see when you look at the thumbnails don't match the bookmarks. Is there also a way to programmatically have the page labels match the bookmarks that are changed as well?

Chris21784797mf9q_0-1665695407342.png

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

Those are crazy looking page labels. Page labels should be short because they are alwasy shown in a small context.

But anyway, you can get the page label for any page with the "doc.getPageLabel" function.

Here's the reference entry:

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#getpagelabel

 

 

   

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

LATEST

Yeah AutoCAD creates those page labels when it produces the PDF.

 

That reference worked perfect though, the SetPageLabels function example on that webpage was able to remove the long one and replace it with just the page number. So yay!

 

Thanks again for all the help 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines