Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 03, 2018 Oct 03, 2018

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

TOPICS
PDF forms
9.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Beginner ,
Oct 04, 2018 Oct 04, 2018
LATEST

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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2018 Oct 03, 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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 03, 2018 Oct 03, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2018 Oct 04, 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!");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 04, 2018 Oct 04, 2018

By generic script, I wanted to be sure I understand how to trap an appropriate event at the level of document or page. I'm not familiar with what events are available at these levels, so I am not confident of how to set up the script. I am looking for general directions that would be something like this...

When a document opens

     do this

      maybe this too

End

When a page is opened

     do this

     and this

End

It would be great to get a list of available events I can use 🙂

Specifically, what I want to do is when the form is opened, I want to run this:

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

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

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

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

As before Gilad, thank you for taking the time to help!

Best,

George

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2018 Oct 04, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 04, 2018 Oct 04, 2018
LATEST

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

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