Learning Centers

Developing with Acrobat Javascript

July 01, 2004

Advertisement
Advertisement
 

Editor's Note: This article is part of the Introduction to Acrobat Development Learning Center

What is Acrobat Javascript?

AcroJS Adobe have integrated a fully fledged scripting language inside Acrobat - Javascript (ECMA Script).

Javascript which has been known in the HTML world for a long time. Javascript which is based on ECMA Script has also been modified to fit inside the confines of the browser. Different Browser vendors (Microsoft, Netscape, Opera) have added to and changed their implementation of Javascript to suit their individual needs - Adobe have done the same thing, created a customised version of ECMA Script that suitís the needs of Acrobat users - AcroJS.

Although Javascript in the Browser and AcroJS share the same common language foundation they operate on completely different Document Object Models (DOMís).

Why use Acrobat Javascript?

Repetitive tasks are the most common reason for using AcroJS. AcroJS allows you to automate tasks that you do manually time and time again, for example you could write some AcroJS that is part of a Batch Sequence to add a series of Bookmarks to a folder of PDF documents.

AcroJS could also be used to insert additional interactivity into a PDF, for example Javascript in Acrobat has the ability to create a custom Popup Menu that is accessed when you right mouse click.

If you have created some PDF Forms and want to ensure your users enter only valid data then you could use AcroJS to validate and control the data entered. For example you could make use of Regular Expressions to validate a Social Security Number or an Email Address (link to new article).

If you have a full version of Acrobat (v5, v6 Std, v6 Pro) we can make use of Templates to create a dynamic PDF. Templates (link) provide a way to dynamically add marked elements to a pre-existing PDF, elements such as graphics, form fields and text.

The Acrobat Document Object Model (ADOM)

The first diagram is a rough mockup of the Internet Explorer Document Object Model (as seen by Javascript). The second diagram is the Acrobat Document Object Model (as seen by Javascript).

Each diagram illustrates the hierarchy of objects in each respective environment.

Web browser

Acrobat (Reader/Standard/Professional)

How do I use Acrobat Javascript

AcroJS levels We can write Javascript for different objects/elements in Acrobat. To access the respective elements or objects we need to place our scripts in the appropriate place. AcroJS can be inserted in the following levels:

  • Folder/Application level
  • Document level
  • Page level
  • Form field level
  • Bookmark/Link level

If you want your AcroJS to be available to all PDF documents that are opened then you can insert them at the Folder level. Basically this means writing code that is placed into a .JS file and placed into the appropriate directory (normally C:\Program Files\Adobe\Acrobat x.0\Acrobat\Javascripts)

Document level scripts reside inside the PDF and are available and accessible to all other elements and scripts in the PDF. (links)

Page level scripts arenít accessible by/from any other elements and can be one or both of the following types: Page Open Action or Page Close Action. (links)

AcroJS placed at the form field level can be placed in various locations:

  • Calculation Script
  • Validation Script
  • Format Script
  • Event triggered Script
  • Keystroke Script

As you can see AcroJS at the Form Field level provides a great number of choices.

When you need to run a script thatís activated when you click a Bookmark or a Link then Acrobat provides this functionality as well.

Limitations and Possibilities

So what canít we do? The single biggest limitation that Javascript has it that it canít access to the outside world - the operating system. This is actually a good thing as it provides users with the confidence that virii, trojans and the like wont ever be a problem.

In version 6 of Acrobat the interaction between plugins and Javascript has become much stronger. This connection illustrates almost limitless possibilities for serious application development inside Acrobat.

Summary

As a rough guess I would say about 75% of Acrobat can be scripted by Javascript, this represents the possibility to save a lot of time through automation.

By far the most attractive featue of AcroJS to myself is the opportunity it provides in the way of Form validation and interactivity. Javascript gave the Web browser itís life and AcroJS does the same for Acrobat.

For the full rundown on Javascript in Acrobat check out the Acrobat Javascript section in the Dev Learning Centre.

More Info

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.