Skip to main content
Inspiring
October 3, 2018
Answered

When a document or a page is opened, how do I run a script?

  • October 3, 2018
  • 1 reply
  • 10917 views

Hi Everyone,

I am looking for a way to run a JS when a document is opened (or when a specific page is opened). For example this will be used to ensure some fields are appropriately hidden but will be made visible when the form is completed.

Is there a way to do this?

Thank you in advance for any help and direction!

George

This topic has been closed for replies.
Correct answer GRBradford

You don't "trap" them. You simply need to place the code in the right locations (the ones I described earlier) and they'll be automatically executed when those events occur.


Thanks Gilad D (try67), your last suggestions took me in the right direction. Also, just as you earlier posted, it's pretty straight forward to find where to place document level scripts in Acrobat Pro DC - just as you mentioned. It's different in the version X.

Here is the generic script I ended up modifying ....

function doMyscript() {

    // Code goes here

}

// Call the function

doMyscript();

And here is the working script...

function HideSignatureFields()

{  this.getField("SupervisorSignature").display = display.hidden;

    this.getField("GenCounselingStudentSignature").display = display.hidden;

    this.getField("PDSignature").display = display.hidden;

    this.getField("ValidateFormFeedback").display = display.hidden;

}

HideSignatureFields();

Thanks again!

Best, George

1 reply

try67
Community Expert
October 3, 2018

You can use a doc-level script to run code when the file is opened (Tools - JavaScript - Document JavaScripts), and a page's Page Open event to run code each time the page is viewed (right-click the page in the Pages panel, select Properties, Actions).

Inspiring
October 4, 2018

It looks like I will need to wait until tomorrow to see where to access these windows: I'm working from home today, and I'm using Acrobat Pro X (v10). At work, I have Acrobat Pro DC. I cannot locate those areas. Where might I look for them in Pro X?

What would generic Open File and Page Open event scripts look like?

And yet again, thank you Gilad D so much for continuing to provide direction and advice.

Best,

George

try67
Community Expert
October 4, 2018

It's pretty much the same in both versions, although it's a bit harder to find under DC.

Not sure what you mean by "generic script"... What do you want that script to do?

If you just want to test it you can use something like this:

app.alert("Hi!");