Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Feb 26, 2020 Feb 26, 2020

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?

 

Acrobat_Bookmark_destination.png

TOPICS
How to
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Feb 26, 2020 Feb 26, 2020

Actually, if you wanted to, you could place that code under a different bookmark and call it "Save Position" or something. It could be just after "HIER" or the last one in the list, or anywhere else. When you click it it will update the HIER bookmark.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2020 Feb 27, 2020

Got it... This does the trick:

Acrobat_Bookmark_destination5.png

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;");

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2020 Feb 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2020 Feb 26, 2020

OK Try67,

 

Thank you for your answer.

 

I have added the script to the bookmark, 

AcrobatScript.jpg

Finished with twice OK.

Now how do I run this script, so the bookmark "HIER" receives the current page as Destiny?

Do I double-click the bookmark? In that case the script changes to:

AcrobatScript2.jpg

(forgive me my ignorance, but I've never worked with script in Acrobat before)

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2020 Feb 26, 2020

Sorry, I wasn't clear enough. That script should not go under the bookmark, because it will get overwritten, as you saw.

You could run it from the JS Console, for example, or even from a menu item or toolbar icon (although you'll need to adjust it a bit and place it in a .js file on the local computer).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2020 Feb 26, 2020

OK ThanX, I'll look into that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2020 Feb 26, 2020

Actually, if you wanted to, you could place that code under a different bookmark and call it "Save Position" or something. It could be just after "HIER" or the last one in the list, or anywhere else. When you click it it will update the HIER bookmark.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2020 Feb 26, 2020

Well Try67,

 

I have found the Custom Tools pane and have added the script succesfuly
(added this.zoomType = zoomtype.fitW; too while doing it)
so I am 98% happy (wish I didn't have to confirm the script every time).

AcrobatScript3.jpg

ThanX for your help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 26, 2020 Feb 26, 2020

Actually have worked out your last suggestion too and that indeed works as a sincle click
(makes  me100% HAPPY):

AcrobatScript4.jpg

ThanX again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2020 Feb 27, 2020

Graag gedaan!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2020 Feb 27, 2020

Any idea, by the way, how I should tweek this script so the result is that the Zoom 150 line becomes part of the HIER output script? I've come to various approaches but no success yet.
This is the current script:

/* 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, "this.zoom = 150", 0);
else this.bookmarkRoot.children[0].setAction("this.pageNum = " + this.pageNum);

 

I have added "this.zoom = 150",  but that doesn't show up in the HIER (result) script:

this.pageNum = 60

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2020 Feb 27, 2020

It has to be a part of the same string, like this:

"this.pageNum = " + this.pageNum + "; this.zoom = 150;"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2020 Feb 27, 2020

Yes, I tried that, but it doesn't work...

This script

Acrobat_Bookmark_destination2.png

does this:

Acrobat_Bookmark_destination3.png

which should be:

Acrobat_Bookmark_destination4.png

to work...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2020 Feb 27, 2020

You have to make the same adjustment to the last line of code, too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2020 Feb 27, 2020

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 27, 2020 Feb 27, 2020

Got it... This does the trick:

Acrobat_Bookmark_destination5.png

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;");
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 31, 2023 Jan 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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 31, 2023 Jan 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 31, 2023 Jan 31, 2023

thanks, Thom. Appreciate your insight. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 31, 2023 Jan 31, 2023
LATEST

No, not with a script, but it can be automated outside of Acrobat, using a stand-alone tool, like this (paid-for) one I've developed: https://www.try67.com/tool/convert-javascript-links-to-real-links

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2020 Feb 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 PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines