Skip to main content
Inspiring
January 30, 2018
Answered

How can I automate the removal and creation of bookmarks?

  • January 30, 2018
  • 3 replies
  • 1045 views

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!

This topic has been closed for replies.
Correct answer Joel Geraci

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.

3 replies

ed_101Author
Inspiring
January 30, 2018

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

Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
January 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.

try67
Community Expert
Community Expert
January 30, 2018

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.