Skip to main content
Participant
April 12, 2020
Question

Loading the same JavaScript into many PDF fields in Acrobat

  • April 12, 2020
  • 1 reply
  • 413 views

I have a custom calculation script that I want to load into two dozen fields on a single page. Adding it to each field one at a time is a colossal pain, especially since I'm still developing the script and need to do it often.

Is there a less painful way to handle this? Does Acrobat have an option to add a script to many fields simultaneously? Or a way to put the script in one central "place" (in Acrobat, or the doc, or even externally) and have the fields pull the script from that place?

 

--------------------------------

 

UPDATE: I ended up using TinyTask to record a screen macro for inserting scripts. That way, I could insert a script by clicking a field and press my hotkey. That allowed me to add 38 scripts in under 5 minutes. Not the solution I was going for, but it's much better and faster than doing it 100% manually.

    This topic has been closed for replies.

    1 reply

    try67
    Community Expert
    Community Expert
    May 19, 2020

    In the future I recommend you post in the Acrobat forum. This one is a bit of a no-man's-land...

     

    Anyway, the answer is yes. You can apply the same script to multiple fields using a for-loop.

    However, it's better if you only apply a call to a function and then place the function itself as a doc-level script.

    That will mean you will only need to update it in a single location in the future, instead of updating each field.

     

    To do that is quite easy. You can use something like this:

    var fields = ["A", "B", "C", "D"];
    for (var i in fields) this.getField(fields[i]).setAction("Calculate", "myCalcFunction();");
    MClark01SAuthor
    Participant
    May 19, 2020

    Thank you. After a couple of weeks of searching, I eventually found that solution. (Your avatar appeared many times throughout those weeks 🙂  Rather than using a function to load the scripts, I added them directly to all the fields by running a script in the JavaScript console. But I may use the fuction/doc-level function you described next time.

     

    Thanks again, and for the tip to use the Acrobat forum.