PDF West. Phoenix, AZ. Nov 2001 ted padova author: Acrobat 5 PDF Bible ted@
west.net http://www.west.net/~ted/pdfwest. JavaScript for. Non-programmers ...
PDF West Phoenix, AZ Nov 2001
JS ava for
Non-programmers
ted padova author: Acrobat 5 PDF Bible
[email protected] http://www.west.net/~ted/pdfwest
cript
You're not making us write more code! Do ya hear me?
OR... taking the monster out of programming.
Ted Padova 1
http://www.west.net/~ted
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ http://www.west.net/~ted/pdfwest
1
• Security • Document Level JavaScripts • Page Templates • Field Attributes • Enable JavaScript Preferences 2
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 2
• Archive commonly used scripts • Build a template • Use bookmarks and comments
3
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 3
Okay, okay, okay... we'll try the semicolon !
Windows only • Using editors Testing JavaScripts • JavaScript Console pp95
4
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 4
Compatibility with Acrobat Viewers • appViewer Version • appViewer Type • Using Page Open
//is Reader (as opposed to Acrobat) if (typeof(app.viewerType)!="undefined") if(app.viewerType == "Reader") { var msg = "You need Adobe Acrobat to complete this form"; app.alert(msg); } else { var msg = "You're viewing this file in Acrobat"; app.alert(msg); }
5
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 5
JavaScript for Page Navigation • Navigating pages • Duplicating Form Fields • Editing duplicated fields scripts this.pageNum=0; //navigates to the first page this.pageNum++; //navigates to the next page this.pageNum--; //navigates to the previous page
6
this.pageNum=this.numPages-1; //last page
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 6
• Performing simple calculations JS vs preset calculations • Calculating sales tax Hiding fields
var f = this.getField ("subtotal"); // the subtotal amount var t = this.getField ("taxrate"); //from a user input field event.value = Math.round (f.value * t.value)/100;
• Calculations in table arrays • Setting Calculation Order 7
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 7
• Creating a template • Document level JavaScripts • Spawning a page from a template this.spawnPageFromTemplate("template");
8
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 8
Version 5.0 of JS Function • addField • Creating page numbers var r = [612-72, 792 - 72, 612, 792]; // inch from upper right
9
for (var i = 0; i < numPages; i++) { var f = this.addField(String("page"+i+1),"text",i,r); f.textSize = 14; f.textColor = color.blue; f.fillColor = color.transparent; f.textFont = font.HelvB; f.borderStyle = border.s; f.strokeColor = color.transparent; f.value = String(i+1); }
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 9
Do we need to use a Stamp?
Acrobat 5.0 JS Function • addAnnot var n = this.getField ("name"); var annot = this.addAnnot ({ page: 71, type: "Text", author: n.value, point: [100, 300, 200, 400], strokeColor: color.blue, popupOpen: true });
10
Stamp
Note
Free
Name
Name
Name
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 10
Document Actions
All right, all right... it's set to go off on a print command.
• Close • Save • Print app.alert("message goes here", 3)
11
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 11
• Using a button import • Password protection for changing images
12
var j = this.getField("holder"); app.beep(2); var n = app.alert("Change image?",2,2); if (n == 4) { var f = app.response("Enter your password"); if (f == "roadrunner") { j.buttonImportIcon(); } else{ if (f!= null) { app.alert("Wrong password!"); } } }
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 12
Hold on... maybe the brackets WILL work!
Creating warning beeps • On Mouse Up • On Mouse Enter app.beep (0);
13
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 13
pp78
• Creating application pop-ups • Navigating to destinations var c = app.popUpMenu (["FirstCategory", "First Selection", "Second Selection, Third Selection], ["SecondCategory", "First Selection", "Second Selection, Third Selection], ["ThirdCategory", "First Selection", "Second Selection, Third Selection],
14
this.gotoNamedDest(c);
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 14
Securing PDF files • Protects JS routines • Prevents changing the document
15
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 15
IDIOT! You didn't write the CGI to collect the data!
• Sending a PDF via email • Sending the FDF data
// use mailForm in this routine // gets the user address from a field // sends FDF data
// use mailDoc in this routine // gets the user address from a field // sends the PDF file
var f = this.getField("useraddress"); this.mailForm(true, f.value, "", "", "Your form data is returned to you");
var f = this.getField("useraddress"); this.mailDoc(true, f.value, "", "", "Your completed PDF form is returned");
16
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 16
• Insurance form • File System
17
Notes: ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ ___________________________________________________ 17