Skip to main content
BartHoeksel
Inspiring
February 26, 2020
Answered

A script to automate setting the destination for a bookmark in Acrobat

  • February 26, 2020
  • 2 replies
  • 4306 views

Hello,

 

I frequently use a bookmark at the top of the Bookmarks List to store the position I stopped reading the last time I was in the document.

 

You do that by first making the bookmark (I called it "HIER"), and then right-clicking the bookmark, selecting "Set Destination" what connects the current page with the bookmark.

 

Is there a way I can automate this or designate this in a script to a button?

 

This topic has been closed for replies.
Correct answer BartHoeksel

[This was a reply I sent to another thread. Don't know why it ended up here...]


Got it... This does the trick:

for who wants to try:

/* Set Current position to HIER */
if (this.bookmarkRoot.children==null || (this.bookmarkRoot.children!=null && this.bookmarkRoot.children[0].name!="HIER"))
this.bookmarkRoot.createChild("HIER", "this.pageNum = " + this.pageNum + ";\nthis.zoom = 150;", 0);
else this.bookmarkRoot.children[0].setAction("this.pageNum = " + this.pageNum + ";\nthis.zoom = 150;");

2 replies

Thom Parker
Community Expert
February 27, 2020

You do know that this solution will only work in Acrobat Pro? And just in general it's not a good solution to modify document structure to save something like the current position. 

A more general solution would use either the global object or a form field. Both of which are intended to be modified in Reader. 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
February 26, 2020

A script can only set the action of a bookmark to a script. If you don't mind that then yes, it's possible.

You can achieve it by executing this JavaScript code:

 

if (this.bookmarkRoot.children==null || (this.bookmarkRoot.children!=null && this.bookmarkRoot.children[0].name!="HIER"))
	this.bookmarkRoot.createChild("HIER", "this.pageNum = " + this.pageNum, 0);
else this.bookmarkRoot.children[0].setAction("this.pageNum = " + this.pageNum);

 

 The code will edit an existing bookmark, or create it if it doesn't exist.

New Participant
January 31, 2023

hey Try, are you saying that the bookmark's Mouse Up Action cannot be changed from "Run JavaScript" to "Go To Page"/fixed destination via automation? 

Thom Parker
Community Expert
January 31, 2023

The Acrobat JavaScript model does not provide functionality for setting any kind of event action to one of the built-in Action types. It can only set an event action to a script. 

See the Reference 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#id642

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often