PDFill | Overview  |  First  |  Previous  |   Next  |  Last

Document Management 12:  Add PDF JavaScript for Document Level

The JavaScript language was developed by Netscape Communications as a means to create interactive web pages more easily. Adobe has enhanced JavaScript so that you can easily integrate this level of interactivity into your PDF documents.

This Set Document Actions command lets you create document-level JavaScript actions that apply to the entire document.

Acro6JSGuide.pdf and AcroJS.pdf shows the detailed information about Acrobat JavaScript Scripting.

Here are some examples:

//Document Level Example 1:  Force Upper Case

var nameField = this.getField('Text 1');
nameField.setAction('Keystroke', 'forceUpperCase()');

function forceUpperCase()
{
    if(!event.willCommit)
        event.change = event.change.toUpperCase();
};

//Document Level Example 2: Validate Age

var ageField = this.getField('ageField');
ageField.setAction('Validate', 'checkAge()');

function checkAge()
{
    if(event.value < 12)
    {
        app.alert('Warning! Applicants age can not be younger than 12.');
            event.value = 12;
    }
};

//Document Level Example 3: Check Comment Characters Length

var commentField = this.getField('commentField');
commentField.setAction('Keystroke', 'checkLength()');

function checkLength()
{
    if(!event.willCommit && event.value.length > 10)
    {
        app.alert('Warning! Comment can not be more than 10 characters.');
        event.change = '';
    }
};

//Document Level Example 4: Insert the current date into a Text Field when the PDF is opened

var f = this.getField("Text1");
f.value = util.printd("mmm/d/yyyy", new Date());

PDFill Copyright © 2002-2010 by PlotSoft L.L.C..  All rights reserved.