Skip to main content
Known Participant
Dec 23, 2016 6:22 PM UTC
Answered

How do I call Javascript function upon opening of PDF

I want to call a Javascript function when a PDF opens or loads. Or when I click this Layer button.

How do I do it? Thanks in advance!

This topic is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Dec 23, 2016 6:55 PM UTC

You can embed a code as a doc-level script and it will execute whenever that file is opened.

You can't assign an action to the opening of the Layers panel, though.

13 replies

Known Participant
Dec 28, 2016 11:18 AM UTC

How do I add a a document-level JavaScript programmatically?

Translate
Known Participant
Dec 28, 2016 12:21 PM UTC

Nevermind. This could be achieved programmatically by adding a Javascript name tree.

Translate
try67
Community Expert
Community Expert
Dec 28, 2016 12:26 PM UTC

What do you mean by "programmatically"? What language are you using to edit the PDF?

If you mean using JS itself, the answer is to use the addScript method of the Document object.

Translate
Inspiring
Dec 23, 2016 6:56 PM UTC

You can define a function in a document-level JavaScript and then place a call to it right after, something like:

// Document-level JavaScript

function doSomething() {

     // Code goes here

}

// Call the function

doSomething();

There is no event that's available to JavaScript when you click the layers button.

Translate
try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
Dec 23, 2016 6:55 PM UTC

You can embed a code as a doc-level script and it will execute whenever that file is opened.

You can't assign an action to the opening of the Layers panel, though.

Translate