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

How can I automate the removal and creation of bookmarks?

Community Beginner ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

Hi,

I have looked at the API and can't seem to figure out how to tinker the bookmark object to do what I need.

I have a PDF that I am assembling from other documents. Once it is fully assembled, I need to 1) remove the bookmarks that are generated (I don't need to keep any) and then I need to 2) add in new bookmarks. I'm currently doing it manually every time the document is assembled. I was attempting to write something that would go to the page I need to insert the bookmark (this.pagenum) and then inserting the bookmark, but was unsuccessful.

Any tips? What successes have you had in adding/removing bookmarks? Is there a better way to do this?


Thank you!

TOPICS
Acrobat SDK and JavaScript

Views

706

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

correct answers 1 Correct answer

Community Expert , Jan 30, 2018 Jan 30, 2018

You are on the right track. Assuming your have a bookmark object already and you are on the page you want to be the destination. You'd set the action of the bookmark like this...

myBookmark.setAction("this.pageNum = "+this.pageNum);

The Action has to resolve into a valid JavaScript that can be executed.

If you are setting the page number in code, remember that PDF pages are zero based; page one is pageNum 0.

Votes

Translate

Translate
Community Expert ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

You should study the methods and properties of the Bookmark object.

Deleting the entire bookmarks tree is very easy. You can do it using this command:

this.bookmarkRoot.remove();

You can then start adding new bookmarks at the root using the createChild or the insertChild methods.

Votes

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 ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

You are on the right track. Assuming your have a bookmark object already and you are on the page you want to be the destination. You'd set the action of the bookmark like this...

myBookmark.setAction("this.pageNum = "+this.pageNum);

The Action has to resolve into a valid JavaScript that can be executed.

If you are setting the page number in code, remember that PDF pages are zero based; page one is pageNum 0.

Votes

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 Beginner ,
Jan 30, 2018 Jan 30, 2018

Copy link to clipboard

Copied

LATEST

Thank you!

I was over complicating it! I ended up doing:

this.bookmarkRoot.remove(); 'this removes the existing bookmarks

this.bookmarkRoot.createChild("Title of bookmark", "this.pageNum = 160"); 'this creates a new bookmark called Title of bookmark on page #161

Votes

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