(Advanced feature of Kofax Power PDF for Mac)
JavaScript is used in Kofax Power PDF for Mac to create custom functions or actions in PDF forms. Javascript commands can be applied to form fields for calculations, formatting, validations, and many other things. Advanced knowledge of JavaScript programming is required to edit existing scripts or add new scripts. Resources that can assist with general or Adobe-specific JavaScript programming are available online through w3schools.com, pdfscripting.com, Adobe, and many other sources.
Note: Kofax Power PDF for Mac only supports JavaScripts for Acroform PDF forms. It does not support JavaScripts for LiveCycle (XFA) documents.
JavaScript is an object-oriented computer programming language. It is commonly used to create interactive effects within web browsers and provides a powerful way to customize PDFs.
Kofax Power PDF for Mac allows you to view, add, delete, or edit existing JavaScripts through a scripting window. JavaScripts in a document lists as either Document scripts or Page scripts. There are generally four types of JavaScript:
Document scripts: document level scripts are scripts at the top of a PDF document’s scripting hierarchy. These scripts are the first ones executed when a document loads in Kofax Power PDF for Mac. Document scripts are used to set up operations, perform top-level environment testing, or define certain functions and variables used by other scripts in the document.
Document actions: document actions are events prompted by an activity such as closing, saving, or printing a document. Document “actions” allow form designers to change the document before or after any of those activities. There are usually five document actions:
Page actions: Page-level actions are events triggered at the page level, such as opening and closing. For example, “opening” a page refers to when the document's specific page is both fully visible, and its associated page number is reflected in the Toolbar. “Closing” a page refers to when the specific page of the document is both no longer fully visible and its associated page number is no longer reflected in the Toolbar. These actions are generally useful for managing pages containing interactive multimedia such as timers, videos, or animations, which Kofax Power PDF for Mac currently may not support.
Annotation actions: Annotation actions are events at the page level associated primarily with form elements for form fields. These actions enable custom functions or formatting for specific annotations. Users will be able to edit or add specific formatting, calculations, or validations for form fields. Form field scripts include two major types of scripts: “Widget scripts” and “Form-value scripts.” Widget scripts are actions performed on a field. Form-value scripts are actions that occur when a form field’s value changes.
Note: Users will be able to view all scripts available at both the Document and Page levels. However, while all scripts are technically editable, Kofax Power PDF for Mac may not support all JavaScripts. As an example, Kofax Power PDF for Mac currently does not support certain multimedia such as interactive videos. However, the application does support general JavaScripts such as alerts, calculations, formatting, and validation.
Before JavaScript can run in a document, it must be enabled in Preferences. (User Preferences).
Enable JavaScript:
The Script window in Kofax Power PDF for Mac allows you to view and edit a document’s JavaScript. If multiple documents are simultaneously open in Kofax Power PDF for Mac, the Script window will display the document's scripts you are actively editing.
Note: Adobe JavaScripts are usually characterized by the prefix “AF.”
The Script window allows you to delete JavaScripts in a PDF. JavaScripts currently included in the document are listed in the left pane.
The Script window allows you to add new scripts to the PDF.
Note: To add an Annotation Action to a specific form field, you must have the form field selected before clicking the plus + to add a script. If you do not have a specific annotation selected, you can only add Document or Page scripts.
There are a couple of ways to test your JavaScript. To execute scripts line by line, use the JavaScript window.
To test your form with calculations, you will need to switch to the Select Text Tool (Command+1) in order to try out your form. Switch back to the Edit Tool (Command+2) in order to edit the appearance of elements you've placed in your form.
Note: JavaScripts will only execute successfully if: