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

Related Products at PDF Store

Nitro PDF Professional OCR

Nitro PDF Professional OCR gives you all the features of Nitro Pro, plus the added power of Optical ... View full product details
Download free demo

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99.99, Nitro PDF Pro is th... View full product details
Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF view... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: Planning for unexpected cash

It's the end of the financial year and some lucky souls are expecting a tax return. Whether or not the dollars are stacking up for you, it's worth keeping in mind this new PDF tool from Squawkfox.

July 29, 2010
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools QuickPDF: The Unrivaled PDF Developer Toolkit