Skip to main content
Participant
Nov 16, 2021 8:50 AM UTC
Question

Get the Bookmark Object of a Clicked Bookmark by Javascript

I want to make bookmarks as bellow using Javascript.
- Each bookmark has a same name as each layers in pdf.
- Each bookmark has the following action.
  When the bookmark is clicked, the only layer with same name as the bookmark will be displayed.
----------------------------------------------
var layers = this.getOCGs();
for (var j in layers){
    this.bookmarkRoot.createChild(layers[j].name, "xxxxxx");
}

----------------------------------------------

 

I want to enter the following script into "xxxxxx". (cExpr augument of createChild method)
----------------------------------------------
var layers = this.getOCGs();
for (var i in layers){
    if (layers[i].name === bookmark.name){
        layers[i].state = true;
     }
    else{
        layers[i].state = false;
    }
}
----------------------------------------------
This script expression is evaluated when the bookmark is clicked
But I can't find how to get the bookmark Object that is being clicked now...
Please give me an advice.
This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

try67
Community Expert
Community Expert
Nov 16, 2021 12:44 PM UTC

You should use a function and pass to it the name of the bookmark that triggers each event as a parameter. Since that name is also the name of the layer you could use that to identify the layer and then show it.

Translate
joyanceAuthor
Participant
Nov 17, 2021 12:50 AM UTC

Thank you for your advice.

Translate
Legend
Nov 16, 2021 9:01 AM UTC

You cannot find the bookmark object last clicked. You'd need to create separate JavaScript for each bookmark, including the name. 

Translate
joyanceAuthor
Participant
Nov 17, 2021 12:49 AM UTC

Your answer was clear and a great help for me.

I resolved it by making another script that generates separate script for each bookmark with each bookmark name.

Thank you!

Translate