I've been struggling with this one for a little while, so thought I'd see if any one else can come up with a solution.
I've been trying to add scripts to specific pages in PDFs. I usually add one script at the document level that applies actions to all buttons within the document, but I then have to manually add scripts to pages.
Is there a way around this that anyone can think of? Can I simply write an event listener for the Page/Open and Page/Close events?
In a nutshell, I'm trying to achieve something like this (using a modified version of the getField function):
this.getPage("1").setAction("Open", "Show('layer1');");
this.getPage("1").setAction("Close", "Hide('layer1');");
this.getPage("3").setAction("Open", "Show('layer1');");
this.getPage("3").setAction("Close", "Hide('layer1');");
If anyone can assist, I'd greatly appreciate it! I don't mind adding these scripts manually to a few pages, but it gets a little tedious when everything else is scripted.
I know that function doesn't work . . . I just wish there was that was as easy for pages as it is for fields!
I thought an custom event listener would have been the way around this, as the Api Reference states:
event
All JavaScript scripts are executed as the result of a particular event. For each of these events, JavaScript
creates an event object. During the occurrence of each event, you can access this object to get and
possibly manipulate information about the current state of the event.
Or does the Page/Open event apply to any page in the document, and therefore can't be modified for specific pages?
I've trawled over the API docs countless times looking for a way to do this, then I usually leave it a few weeks until it comes up again, and I still can't figure out a way to apply a script to specific pages. Gilad - if you can help point me in the right direction to start the loop, that would be fantastic!
-dean
If you read the documentation of setPageAction(), you've seen that the first parameter is the page number.
So if you defined which pages you want to apply this script to, you can change that number in a loop.
Something like this can be executed from the console:
var pages = [ 0,1,2,10]; // These are the pages we want to add the script to
for (var i in pages) {
this.setPageAction(pages[i], "Open", "Show('layer1');");
this.setPageAction(pages[i], "Close", "Hide('layer1');");
}
North America
Europe, Middle East and Africa
Asia Pacific