bc. JavaScript in Acrobat Forms. ▫ Brief Introduction. ▫ Examples. Page 4. bc.
Brief Introduction. ▫ JavaScript is a programming language. ▫ Defined by ...
®
b c
Inspiration becomes reality.™ www.Adobe.com www.Adobe.com
b c
©2000 Adobe Systems Incorporated. All rights reserved.
February 2000
Using JavaScript with Acrobat Forms James C. King A Principal Scientist
b c
JavaScript in Acrobat Forms n n
bc
Brief Introduction Examples
Brief Introduction n
JavaScript is a programming language Defined by Netscape n Object oriented n Classes: Boolean, Number, Date, Math, String,and Array. n
n
Has been specialized for Acrobat use Predefined classes and objects n Objects: app, console, doc, event, field, global, util and of course this. n
bc
Brief Introduction n
Learn Acrobat Forms in stages The basics n Validate, calculate, actions n Submit and receive with WWW Server n Scripting simple things n Scripting programs n
n
Learn by Example Copy and modify example scripts n Can do a lot with very simple scripts n
bc
Documentation n
Two important documents JSSpec.pdf n AcroJS.pdf n
n
Found in the Acrobat “Help” folder n
bc
See especially “Field Properties” section of AcroJS.pdf
Alerts n
Example -- before typing into field n
Field A:
Field A -- Actions Script: app.beep(0); app.alert("Please be accurate while typing into this field.");
bc
Asking Questions n
Example -- accessing other fields n
Field B:
Field B -- Actions Script: app.beep(0); var happy = app.alert("Are you happy?", 3, 2); var h = this.getField("HappyFace"); var s = this.getField("SadFace"); if (happy == 4) {h.hidden = false; s.hidden = true;} else {h.hidden = true; s.hidden = false;}
bc
Mouse overs n
Example -- changing properties n
Field C:
Adobe Systems Incorporated Field C -- Actions Script on Mouse Enter: var f = this.getField("FieldC"); f.fillColor = color.yellow; f.strokeColor = color.blue; f.textColor = color.black;
bc
Field C -- Actions Script on Mouse Exit: var f = this.getField("FieldC"); f.fillColor = [ "CMYK", 1.0, 0.2, 0.2, 0.0]; f.strokeColor = color.yellow; f.textColor = ["RGB", 1, 1, 1];
Calculate Script n
Example -- complicated sums
Cost
* Quantity
=
Total
Cost.0
$2.00
1
Cost.1
1 Cost.2
1 Cost.3
1
bc
$2.00 Total -- Calculate Script var L1 = "Cost"; var L2 = "Quantity"; var N = 4; var sum = 0; for (var i = 0; iForms->Document JavaScripts” Plug-in Level -- in “Plug-ins/AcroForms/JavaScript” folder
Levels of Scripts n
Example Document Level -- Change all backgrounds Mouse Up Action:
Push Me!
for (var i=0; i