event Page/Open through script?

New Here ,
Dec 28, 2018

Copy link to clipboard

Copied

I'd like to run a script dynamically at every page, without executing a menu item or running the console at every page change, and not manually as described in this tutorial

https://acrobatusers.com/tutorials/entering-page-actions

I've tried at the folder-level and document-level script

if (event.type === 'Page' && event.name === 'Open') {

    app.alert('test')

}

Nothing happened when pages changed.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

There isn't one. There's no "event handler" that will execute each time you open any page. All events are tied to a specific page, field, bookmark, etc. The only generic events are at the doc-level, when you open it, close it, save it, print it, etc.

TOPICS
Acrobat SDK and JavaScript

Views

178

Likes

Translate

Translate

Report

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

event Page/Open through script?

New Here ,
Dec 28, 2018

Copy link to clipboard

Copied

I'd like to run a script dynamically at every page, without executing a menu item or running the console at every page change, and not manually as described in this tutorial

https://acrobatusers.com/tutorials/entering-page-actions

I've tried at the folder-level and document-level script

if (event.type === 'Page' && event.name === 'Open') {

    app.alert('test')

}

Nothing happened when pages changed.

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

There isn't one. There's no "event handler" that will execute each time you open any page. All events are tied to a specific page, field, bookmark, etc. The only generic events are at the doc-level, when you open it, close it, save it, print it, etc.

TOPICS
Acrobat SDK and JavaScript

Views

179

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 28, 2018 0
Most Valuable Participant ,
Dec 28, 2018

Copy link to clipboard

Copied

You can't do it like that. You can use a script to apply the same code to each page's Open event, though.

The code to use would be:

for (var i=0; i<this.numPages; i++) {

    this.setPageAction(i, "Open", "app.alert('test');");

}

Run this code once from the JS Console and all the pages will be edited.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2018 2
New Here ,
Dec 28, 2018

Copy link to clipboard

Copied

Thanks, your solution works, though I'm still wondering what's some practical way to use the API's event Page/Open.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2018 0
Most Valuable Participant ,
Dec 28, 2018

Copy link to clipboard

Copied

There isn't one. There's no "event handler" that will execute each time you open any page. All events are tied to a specific page, field, bookmark, etc. The only generic events are at the doc-level, when you open it, close it, save it, print it, etc.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 28, 2018 2