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!
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.
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.
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.
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