How can I automate the removal and creation of bookmarks?

Community Beginner ,
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!

Adobe Community Professional
Correct answer by Joel_Geraci | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript

Views

259

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

How can I automate the removal and creation of bookmarks?

Community Beginner ,
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!

Adobe Community Professional
Correct answer by Joel_Geraci | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript

Views

260

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
Jan 30, 2018 0
Most Valuable Participant ,
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.

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
Reply
Loading...
Jan 30, 2018 2
Adobe Community Professional ,
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.

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
Reply
Loading...
Jan 30, 2018 1
ed_101 LATEST
Community Beginner ,
Jan 30, 2018

Copy link to clipboard

Copied

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

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
Reply
Loading...
Jan 30, 2018 0