Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Running Javascript code that is not in the form??

Avatar

Former Community Member
Is it possible to have a pdf form run javascript that is located in a seperate file. For example, I want the user to push a button on the form which causes the form to open a file which contains javascript. The form then runs the javascript in the file as if the javascript.



Basically I want the ability to easily change what the button does without having to distribute a new Form.
4 Replies

Avatar

Former Community Member
No; the script must be in the XDP / PDF.



You can make SOAP calls; perhaps you can use that combined with JavaScript's eval() to feed in new code from the server that served the PDF.

--

SteveX

Adobe Systems

Avatar

Former Community Member
There is one other way, you'd put the code in a .js file which MUST be in Acrobat's JavaScript folder. The button could call a method defined in the .js file. Then if you want to switch what it does you would need to replace the .js file on the client's machine (which may not help you either). Also, when doing this, Acrobat will evaluate these scripts on startup, so if you change the file the new functionality will not take place until Acrobat is restarted.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Thank you Chris for the suggestion on using a Folder-Level javascript file for my situation. I think it may be the way I want to go. However, I am having problems figuring out how to reference a Field Object through Folder-Level javascript.



I have a document created in Developer with a text field called "txtCompanyName". As a test I was trying to get the Folder-Level javascript to simply app.alert the contents of the txtCompanyName field. This is the code I have tried:



function TestMe()

{

app.alert(this.getField("txtCompanyName");

}



I have a button on my PDF whose mouseup event calls TestMe(). Nothing happens when the event fires. If I have

app.alert("Test")

in the Folder Level javascript it works.



The full context for the field is:

form1[0].frmMain[0].txtCompanyName[0]



Thank you for your help.

Avatar

Former Community Member
Ok, so since you are working with a Designer based PDF, this doesn't refer to the Acrobat Document object, but event.target will. So your function should look like:



function TestMe()

{

app.alert(event.target.getField("form1[0].frmMain[0].txtCompanyName[0]").value);

}



Chris

Adobe Enteprise Developer Support