Q: Does Qoppa’s PDF library products support JavaScript?
A: Yes, Qoppa’s Java PDF SDK API has support JavaScript.
How is JavaScript used in PDF documents?
Mostly, JavaScript is used in interactive PDF forms in field actions to calculate the value of fields, validate field data to prevent invalid entry and format special fields such as dates, ssn, postal codes, phone numbers, etc…JavaScript can also be associated with other actions such as the Open Document action, for instance to prompt the user for data or silently print the document.
Turning on JavaScript
By default, in all of Qoppa’s Java PDF libraries, JavaScript is disabled for all PDF documents. It is rare that JavaScript is used in unattended processes, on the server-side.
By default, all Qoppa’s PDF components will prompt user to choose whether to enable or disable JavaScript when opening a JavaScript-enabled PDF form.
To turn JavaScript on, for all JavaScript-enabled PDF forms, make the following static call before loading any PDF form:
JavaScriptSettings.setJSEnabled(new JavaScriptEnabler(true)); |
The argument to this method is an object that implements IJavaScriptEnabler, the JavaScriptEnabler class used in this sample is a simple implementation of this interface that is always true or false. An application can create its own implementation of the interface to decide whether to enable JavaScript depending on the document or any other external criteria.
Note that the rhino jar file rhino.jar is required in the class path for JavaScript to run. If the jar file is not present, JavaScript will not give any error but simply not run. This jar can be found under the installation folder of the library demo program.
What events are supported?
List of Supported JavaScript Events.
What Objects / Methods / Properties are supported?
List of Supported JavaScript Objects, Methods and Properties.
What JavaScript Actions are supported?
List of Supported JavaScript Actions
Acroform versus XFA JavaScript
We mostly support “Acroform” JavaScript, that is script that is added to a PDF using Acrobat Pro’s form editing mode (not Livecycle). We have limited support for JavaScript information stored in XFA.
How to script JavaScript?
For more information about how to script, see Acrobat JavaScript Scripting Reference.