Home » Acrobat 9, PDF JavaScript

How to Find Scripts in a PDF

2 Feb 2009 | | No Comment

WindjackEditors note: Yet another valuable contribution by Thom Parker, CEO of WindJack Solutions (Acrobat plug-in experts) and also host of pdfscripting.com which has a very specific focus on making PDF Scripting accessible to any from the novice to the expert. In today’s post, Thom looks to explain the relationship between Acrobat, PDF, and scripts.

By Thom Parker, www.pdfscripting.com

For Acrobat/PDF forms, Don’t miss the Live Sample at end of the article.

One of the biggest issues that PDF newcomers face is understanding the relationship between Acrobat, PDF, and scripts. It’s not just you, this really is a confusing issue. It turns out that scripting is unbelievably useful for all kinds of stuff. Since its introduction in Acrobat 3, Adobe has continued to find new ways to use scripts in the Acrobat/PDF environment, stuffing them into the most unlikely places.

Copying functionality from a sample PDF to your own document almost always means finding scripts on the sample. But for 99% of PDF functionality you don’t need to be an expert to do this. Really, there are only a few key ideas that are necessary.

PDF Scripting Locations

First, JavaScript (Acrobat’s scripting language) is event driven. All scripts are run as a direct result of some action, such as the user clicking on a button or entering data into a field. Second, in the scripting world, a PDF is viewed as a hierarchy, or tree of objects. There is an object for the whole document. Inside the document object, there is an object for each form field, each bookmark, each annotation, each multimedia display, etc. So to put this all together, in a PDF a script is associated with an action on an object. For example, if you enter data into a form field and then click or tab out of the field, you might get popup message that says the data is invalid and you need to re-enter it. This is the result of a “Validation” event script on that field.

So now we know how scripts are associated with things on the PDF, but how do we access those scripts?

Accessing Scripts

Select Object Tool

Select Object Tool

The sample document on the next page is a live PDF form, with lots of scripts. There are Note annotations explaining how to find those scripts and some alternatives on where a script that performs a particular action may be located.
 
To help you find scripts associated with a form field you’ll need to use the “Select Object.” This tool is activated from the Advanced Editing Toolbar. This is the arrow button at the far left on the toolbar. Activating it puts Acrobat into a kind of edit mode. All the form fields are outlined and the field names are displayed. Right click on any form field and from the popup menu select “Properties.”

The properties dialog has several tabs across the top. Some of these are for accessing scripts associated with events on the form field. The “Actions” tab is for mouse and focus events, the validate tab is for the validation script, the calculate tab is for a calculation script, etc. Not all fields have all of these tabs. It depends on the field type.

You’ll find that the properties dialogs for other scripting locations are similar.

You can download a complete live sample, including this article along with a JavaScript enabled PDF file at, Finding Scripts on a PDF page” (right-cick and Save As to download to your computer).

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave your response!

You must be logged in to post a comment.