Skip to main content
Inspiring
Jan 30, 2018 5:20 PM UTC
Answered

How can I automate the removal and creation of bookmarks?

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 is closed to new replies. Start a new post to keep the conversation going.
Joel Geraci
Joel GeraciCorrect answer
Community Expert
Jan 30, 2018 5:31 PM UTC

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
Jan 30, 2018 7:44 PM UTC

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

Translate
Joel Geraci
Community Expert
Joel GeraciCommunity ExpertCorrect answer
Community Expert
Jan 30, 2018 5:31 PM UTC

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.

Translate
try67
Community Expert
Community Expert
Jan 30, 2018 5:28 PM UTC

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.

Translate