Adobe Acrobat: Acrobat Forms Javascript Object Specification
Adobe Acrobat: Acrobat Forms Javascript Object Specification
Adobe Acrobat
1999 Adobe Systems Incorporated. All rights reserved. The information in this document is furnished for informational use only, is subject t change without notice, and should not be construed as a commitment by Adobe Systems Incorporated. Adobe Systems Incorporated assumes no responsibility or liability for any errors or inaccuracies that may appear in this document. The software described in this document is furnished under license and may only be used or copied in accordance with the terms of such license. Adobe, the Adobe logo, Acrobat, Acrobat Capture, Acrobat Exchange, and Distiller are trademarks of Adobe Systems Incorporated. Microsoft and Windows are registered trademarks and ActiveX is a trademark of Microsoft in the U.S. and other countries. Macintosh is a trademark of Apple Computer, Inc. registered in the U.S. and other countries. PowerPC is a trademark of International Business Machines Corporation. UNIX is a registered trademark in the U.S. and other countries, licensed exclusively through X/Open Co. Ltd. All other products or name brands are trademarks of their respective holders.
Table Of Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Other useful documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Document Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Whats New for 4.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Acrobat Forms JavaScript Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 App Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 App Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 calculate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 formsVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 fullscreen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 numPlugIns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 openInPlace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 toolbarHorizontal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 toolbarVertical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 viewerType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 viewerVersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 App Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 alert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 beep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 execMenuItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 getNthPlugInName. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 goBack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 goForward . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 hideMenuItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 hideToolbarButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 mailMsg. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Color Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Color Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Color Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Console Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Console Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 show . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 hide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 println . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
iii
Doc Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Doc Access from JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Doc Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 calculate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 creator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 creationDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 delay. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 dirty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 external . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 filesize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 modDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 numFields. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 numPages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 numTemplates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 pageNum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 producer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 subject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 zoom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 zoomType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Doc Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 calculateNow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 exportAsFDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 getField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 getNthFieldName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 getNthTemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 getURL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 gotoNamedDest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 importAnFDF. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 mailDoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 mailForm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 resetForm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 scroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 spawnPageFromTemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 submitForm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Event Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Event Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Mouse Enter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Mouse Down . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Mouse Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Mouse Exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
iv
Keystroke . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Validate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Calculate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Event Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 commitKey. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 modifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 rc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 selEnd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 selStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 willCommit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Field Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Field Access from JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Field Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 borderStyle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 calcOrderIndex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 charLimit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 defaultValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 doc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 editable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 fillColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 hidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 highlight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 lineWidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 multiline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 numItems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 print . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 readonly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 strokeColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 textColor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 textFont . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 textSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 userName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Field Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 buttonImportIcon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 clearItems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 deleteItemAt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 getArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 getItemAt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 insertItemAt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 setItems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Global Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Global Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 setPersistent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 this Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Variable and Function Name Conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Util Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Util Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 printx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 printd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 scand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Implementation Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 JavaScript Locations and Loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Plug-in folder level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Document level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Field level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Form Field Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Form Field Hierarchies with JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 Working With The Date Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Converting a Date to a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Converting a String to a Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Date Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Acrobat Forms and Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Restricting Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Restricting Permissions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Digital Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 Working with Signature Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
vi
with the Adobe Acrobat Plug-ins SDK CD-ROM or on the Adobe Web site http:// beta1.adobe.com/ada/acrosdk/DOCS/VWRPIREF.PDF.
Document Conventions
As this document pertains to Acrobat Forms version 3.5 and greater, there exists some compatibility issues with older versions of the software. If a property, method, or object is marked with a #.# symbol, then it is available only in versions of the Acrobat Forms software greater than or equal to #.#. Before accessing this object, property, or method, the script should check that the application version is greater than or equal to #.# if backwards compatibility is desired. Example:
if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.0) { // Perform version specific operations. }
As the JavaScript extensions to Acrobat Forms have evolved, some properties or methods have been superseded by other, more flexible or appropriate properties or methods. The use of these older methods are discouraged and marked by Mr. Unhappy.
display
Note:
Items shown in italics are not new to this release but they have been modified or added to.
App Object
The App object is a static JavaScript object that defines a number of Acrobat specific functions plus a variety of utility routines and convenience functions.
If this property is set to true, it will allow calculations to be performed. If set to false, this property prevents all calculations in all documents from happening. Its default value is true. See also the document calculate property which supersedes this property in later versions.
4.0
This property indicates the version number of the forms software running inside the viewer. Use this method to determine whether objects, properties, or methods in newer versions of the software are available if you wish to maintain backwards compatibility in your scripts. See Document Conventions for more details. Example:
if (typeof app.formsVersion != "undefined" && app.formsVersion >= 4.5) { // Perform version specific operations here. }
10
This property puts the Acrobat viewer in fullscreen mode vs. regular viewing mode. Example:
// on mouse up, set to fullscreen mode app.fullscreen = true;
In the above example, the Adobe Acrobat viewer is set to fullscreen mode when app.fullscreen is set to true. If app.fullscreen was false then default viewing mode would be set. The default viewing mode is defined as the original mode the Acrobat application was in before full screen mode was initiated.
This property defines the language of the running Acrobat Viewer. It returns the following strings:
String DEU ENU ESP FRA ITA JPN NLD SVE Language, Country German, Germany English, The United States of America Spanish, Spain French, France Italian, Italy Japanese, Japan Dutch, The Netherlands Swedish, Sweden
4.0
This property indicates the number of plug-ins that have been loaded by Acrobat. See also the getNthPlugInName method.
4.0
This property determines whether cross-document links are opened in the same window or opened in a new window.
11
This property returns the platform that the script is currently executing on. Valid values include WIN, MAC, and UNIX.
This property allows a script to show or hide both the horizontal and vertical Acrobat tool bars. It does not hide the tool bar in external windows (i.e. in an Acrobat window within a Web browser). Example:
// Opened the document, now remove the toolbar. app.toolbar = false;
4.0
This property allows a script to show or hide the Acrobat horizontal tool bar. It does not hide the tool bar in external windows (i.e. in an Acrobat window within a Web browser).
4.0
This property allows a script to show or hide the Acrobat vertical tool bar. It does not hide the tool bar in external windows (i.e. in an Acrobat window within a Web browser).
This property determines if the running Acrobat Viewer is the Reader vs. Exchange. Its value is Reader or Exchange respectively.
4.0
This property indicates the version number of the current viewer (i.e. Reader or Exchange).
12
This method returns the type of the button that was pressed by the user:
Button Type Error OK Cancel No Yes Value 0 1 2 3 4
13
This method causes the system to play a sound. The various sounds and the values used are as follows:
Message Type Error (default) Warning Question Status Default Value 0 1 2 3 4
4.0
This method executes the specified menu item. To find out the exact menu item name, see the Acrobat Viewer Plug-in API On-line Reference under Lists: Menu item names. The menu item name is case sensitive and has to exactly match strings in the list. Example:
/* This example executes File->Open menu item. It will display a dialog to the user asking for the file to be opened. */ app.execMenuItem("Open");
Note:
For security reasons, we will not allow the script to execute the SaveAs and Close menu items. If either of those two menu items is passed as cMenuItem, this function will do nothing.
4.0
This method returns the name of the Nth plug-in that has been loaded by the viewer. See also the numPlugIns property.
14
goBack Parameters: None Returns: nothing Use this function to go to the previous view on the view stack. This is equivalent to pressing the go back button on the Acrobat tool bar.
goForward Parameters: None Returns: nothing Use this function to go to the next view on the view stack. This is equivalent to pressing the go forward button on the Acrobat tool bar.
4.0
This method only works in the Config.js Plug-in folder level script. It allows a forms integrator to customize the look of the Acrobat viewer by removing the menu item specified by cName. Language independent names for toolbar buttons can be obtained from the Acrobat Viewer Plug-In API On-line Reference (Technical Note #5168). See Other useful documents for more details.
4.0
This method only works in the Config.js Plug-in folder level script. It allows a forms integrator to customize the look of the Acrobat viewer by removing the toolbar button specified by cName. Language independent names for toolbar buttons can be obtained from the Acrobat Viewer Plug-In API On-line Reference (Technical Note #5168). See Other useful documents for more details.
mailMsg Parameters: bUI, cTo, [cCc], [cBcc], [cSubject], [cMsgBody] Returns: nothing
4.0
This method sends out an e-mail message with or without user interaction depending on the value of bUI. If it is set to true then the rest parameters are used to seed the compose new message window that is displayed to the user.
15
If bUI is set to false, the cTo parameter is required and others are optional. You must use a semicolon ; to separate multiple recipients in cTo, cCc, cBcc parameters. The length limit for cSubject and cMsgBody is 64k bytes. Example:
/* This will pop up the compose new message window */ app.mailMsg(true); /* This will send out the mail to [email protected] and [email protected] */ app.mailMsg(false, "[email protected]; [email protected] ", "", "", "This is the subject", "This is the body of the mail.");
Note:
This is a Windows-only feature. In addition, the client machine must have its default mail program configured to be MAPI enabled in order to use this method.
response Parameters: cQuestion [cTitle], [cOldValue] Returns: cResponse or null on cancel This method displays a dialog box containing a question and an entry field for the user to reply to the question. Optionally, the dialog may have a title or a default value for the answer to the question. The return value is a string containing the users response. If the user presses the cancel button on the dialog the response is the null object.
16
Color Arrays
A color is represented in JavaScript as an array containing 1, 2, 4, or 5 elements corresponding to a transparent, gray, RGB, or CMYK color space, respectively. The first element in the array is a string denoting the color space type. The subsequent elements are numbers that range between zero and one inclusive. The following table illustrates this:
Color Space String # of Additional Elements 0 1 3 4
T G RGB CMYK
For example, the color red can be represented as [RGB 1 0 0]. Invalid strings or insufficient elements in a color array cause the color to be interpreted as the color black. A transparent color space indicates a complete absence of color and will allow those portions of the document underlying the current field to show through. Colors in the gray color space are represented by a single valuethe intensity of achromatic light. In this color space, 0 is black, 1 is white, and intermediate values represent shades of gray (i.e. .5, .7 etc.). Colors in the RGB color space are represented by three values: the intensity of the red, green, and blue components in the output. RGB is commonly used for video displays because they are generally based on red, green, and blue phosphors. Colors in the CMYK color space are represented by four values. These values are the amounts of the cyan, magenta, yellow, and black components in the output. This color space is commonly used for color printers, where they are the colors of the inks traditionally used in four-color printing. Only cyan, magenta, and yellow are necessary, but black is generally used in printing because black ink produces a better black than a mixture of cyan, magenta, and yellow inks, and because black ink is less expensive than the other inks.
Color Object
The color object is a convenience static object that defines the basic colors. These colors are accessed in JavaScripts via the color object. Use this object whenever you want to set a property or call a method that require a color array. The color object is defined in AForm.js.
17
Color Properties The color object defines the following colors and there associated keywords:
Color Object Transparent Black White Red Green Blue Cyan Magenta Yellow Dark Gray Gray Light Gray Keyword color.transparent color.black color.white color.red color.green color.blue color.cyan color.magenta color.yellow color.dkGray color.gray color.ltGray Version
Example:
// This example sets the text color of the field to red // if the value of the field is negative, else it sets it // to black. var f = event.target; /* field that the event occurs at */ if (event.value < 0) f.textColor = color.red; else f.textColor = color.black;
18
Console Object
The Console object is a static object to access the JavaScript console for displaying debug messages. It functions only within Acrobat Exchange.
Console Methods
show Parameters: none Returns: none This method shows the console window.
hide Parameters: none Returns: none This method closes the console window.
println Parameters: cMessage Returns: none This method prints the string value of cMessage to the console window with an accompanying carriage return. Example:
// This example prints the value of a field to the console window var f = event.target; console.println("Field value = " + f.value);
clear Parameters: none Returns: nothing This method clears the console windows buffer of any output.
19
Doc Object
The JavaScript Doc object provides the interfaces between a PDF document open in the viewer and the JavaScript interpreter. It provides methods and properties of the PDF document.
4.0
If this property is set to true, it will allow calculations to be performed for this document. If set to false, this property prevents all calculations from happening for this document. Its default value is true. This property supersedes the application level calculate property whose use is now discouraged.
This property defines the creator of the document (e.g. Adobe FrameMaker, Adobe PageMaker, etc.).
20
4.0
This property delays the redrawing of any appearance changes to every field in the document. It is generally used to buffer a series of changes to fields before requesting that the fields regenerate their appearance. Setting the property to true forces all changes to be queued until delay is reset to false. Once set to false then all the fields on the page are re-drawn. See also the field level delay property.
This property identifies whether the document has been dirtied as the result of a changes to the document (and therefore needs to be saved). It is useful to reset the dirty flag in a document when performing changes that do not warrant saving, for example, updating a status field in the document.
var f = this.getField("Status"); var b = this.dirty; f.value = "Press the reset button to clear the form."; this.dirty = b;
4.0
This property indicates whether the current document is being viewed in the Acrobat application or in an external window (such as a web browser).
21
This property specifies the documents keywords in the Adobe Acrobat File->Document Info>General dialog box.
This property contains the date the document was last modified.
4.0
This property returns the total number of fields in the document. See also the getNthFieldName method.
This property returns the number of templates in the document (see also getNthTemplate and spawnPageFromTemplate methods).
This property defines the device independent path of the document, for example /Acrobat3/ Exchange/doc.pdf
22
Use this property to get or set a page of the document. When setting the pageNum to a specific page, remember that the values are 0 based.
// This example will go to the first page of the document. this.pageNum = 0 ;
This property contains producer of the document (e.g. Acrobat Distiller, PDFWriter, etc.).
Use this property it to get or set the current page zoom level. The values allowed are 12% and 800% specified as an integer. Example:
// This example will zoom in to twice the current zoom level. this.zoom *= 2; // This now sets the zoom to 200% this.zoom = 200;
23
This property specifies the current zoom type of the document. Valid zoom types are: none, fit page, fit width, fit height, and fit visible width. A convenience zoomType object that defines all the valid zoom types is provided for use from JavaScript. It provides the following zoom types:
Zoom Type NoVary FitPage FitWidth FitHeight FitVisibleWidth Preferred Keyword zoomtype.none zoomtype.fitP zoomtype.fitW zoomtype.fitH zoomtype.fitV zoomtype.pref
Example:
// This example sets the zoom type of the document to fit the width. this.zoomType = zoomtype.fitW;
4.0
Use this method to export an FDF file to the local hard drive. Upon invocation, a dialog will be shown to let the user select the file to export to. The optional bAllFields parameter indicates, if true, that all fields are exported, including those that have no value, and if false (the default) to exclude those that currently have no value. The optional bNoPassword parameter indicates, if true (the default), not to include in the exported FDF text fields that have the password flag set.
24
The optional aFields parameter is the array of field names to submit or a string containing a single field name. If this parameter is present then only the fields indicated are exported, except those excluded by parameter bEmpty or bNoPassword. If this parameter is omitted or is null then all fields in the form are exported (again subject to the restrictions of bEmpty). You can include non-terminal fields in the array or the string passed as a parameter: this is a simple shortcut for having a whole subtree exported. Example:
/* Export the entire form (including empty fields) with flags. */ this.exportAsFDF(true, true, null, true); /* Export the name subtree with no flags. */ this.exportAsFDF(false, true, name);
The example above illustrates a shortcut to exporting a whole subtree. Passing name as part of the aFields parameter, exports name.title, name.first, name.middle and name.last, etc. The optional aFlags parameter indicates, if true, that field flags should be included in the exported FDF. The default is false. This method does not work in the Acrobat Reader.
getField Parameters: cName Returns: object Use this function to map a field object in the PDF document to a JavaScript variable. The cName parameter is the name of the field of interest. This function returns a Field JavaScript object representing the form field in the PDF document.
4.0
Use this function to obtain the nth field name in the document (see the numFields property). Example:
// Enumerate through all of the fields in the document. for (var i = 0; i < this.numFields; i++) { console.println("Field[" + i + "] = " + this.getNthFieldName(i)); }
25
getNthTemplate Parameters: nWhich Returns: cName Use this function to retrieve the name of a template within in the document. (See also the numTemplates property and spawnPageFromTemplate method.)
4.0
This method retrieves the specified URL over the internet using a GET. If the current document is being viewed inside the browser or Acrobat Web Capture is not available, it uses the Weblink plug-in to retrieve the requested URL. If bAppend is true (the default) and Acrobat Web Capture is available, the resulting pages are appended to the current document.
gotoNamedDest Parameters: cName Returns: nothing Use this method to go to a named destination within the PDF document. For more details on named destinations and how to create them, see the PDF Reference Manual Version 1.3
4.0
This method imports the specified FDF file. The cFile parameter specifies the deviceindependent pathname to the FDF file. See Section 7.4 of the PDF Reference Manual for a description of the device-independent pathname format (it should look like the value of the /F key in an FDF exported via the exportAsFDF method or via the File->Export->Form Data menu item). The pathname may be relative to the location of the current document. If the parameter is omitted a dialog will be shown to let the user select the file. This method does not work in the Acrobat Reader.
mailDoc Parameters: bUI, cTo, [cCc], [cBcc], [cSubject], [cMsgBody] Returns: nothing
4.0
This method saves the current PDF document and mails it as an attachment to all recipients with or without user interaction depending on the value of bUI. If it is set to true then the rest
26
of the parameters are used to seed the compose new message window that is displayed to the user. If bUI is set to false, the cTo parameter is required and all others are optional. You must use a semicolon ; to separate multiple recipients in cTo, cCc, cBcc parameters. The length limit for cSubject and cMsgBody is 64k bytes. Example:
/* This will pop up the compose new message window */ this.mailDoc(true); /* This will send out the mail with the attached PDF file to [email protected] and [email protected] */ this.mailDoc(false, "[email protected]", "[email protected]", "", "This is the subject", "This is the body.");
Note:
This is a Windows-only feature. In addition, the client machine must have its default mail program configured to be MAPI enabled in order to use this method.
mailForm Parameters: bUI, cTo, [cCc], [cBcc], [cSubject], [cMsgBody] Returns: nothing
4.0
This method exports the form data and mails the resulting FDF file as an attachment to all recipients, with or without user interaction depending on the value of bUI. If it is set to true then the rest of the parameters are used to seed the compose new message window that is displayed to the user. If bUI is set to false, the cTo parameter is required and all others are optional. You must use a semicolon ; to separate multiple recipients in cTo, cCc, cBcc parameters. The length limit for cSubject and cMsgBody is 64k bytes. Example:
/* This will pop up the compose new message window */ this.mailForm(true); /* This will send out the mail with the attached FDF file to [email protected] and [email protected] */ this.mailForm(false, "[email protected]; [email protected]", "", "", "This is the subject", "This is the body of the mail.");
27
Note:
This is a Windows-only feature. In addition, the client machine must have its default mail program configured to be MAPI enabled in order to use this method.
print Parameters: bInteractive, [nFirstPage], [nLastPage], [bSilent] Returns: nothing Use this function to print all or a specific number of pages of the document. If bInteractive is true, Acrobat displays the standard print dialog and all other parameters are ignored. The optional nFirstPage and nLastPage parameters specify the range of pages to print. If using nFirstPage and nLastPage parameters bInteractive must be false. Set the optional bSilent flag to true if you dont want to display the cancel dialog box while the document is printing. The default value for bSilent flag is false. Example:
// This Example will print current page the document is on this.print(false, this.pageNum, this.pageNum);
resetForm Parameters: [aFields] Returns: nothing Use this method to reset the field values within a document. If the aFields parameter is present, then only the fields indicated are reset. If not present or null then all fields in the form are reset. You can include non-terminal fields in the array. Use this as a simple shortcut for having a whole subtree reset. For example, if you pass name as part of the fields array then name.first, name.last, etc. will be reset.
var fields = new Array(2); fields[0] = "P1.OrderForm.Description"; fields[1] = "P1.OrderForm.Qty"; this.resetForm(fields);
28
Use this function to scroll the current page to the location specified by xOrigin and yOrigin. These coordinates must be defined in user space. Please refer to the PDF Reference Manual Version 1.3 for more details on the user space coordinate system.
spawnPageFromTemplate Parameters: cTemplate, [nPage], [bRename], [bInsert] Returns: nothing Use this method with a template name, such as the ones returned by getNthTemplate. The optional parameter nPage, represents the page number (zero-based) into which the template will be spawned. If that page already exists, then the template contents are appended to that page. If nPage is omitted, a new page is created at the end of the document. The optional parameter bRename, is a boolean that indicates whether fields should be renamed. The default for bRename is true. Example:
var n = this.numTemplates; var cTempl; for (i = 0; i < n; i++) { cTempl = this.getNthTemplate(i); this.spawnPageFromTemplate(cTempl); }
4.0 Addition
If bInsert is specified then the template is inserted before the page specified by nPage as opposed to being overlaid on top of that page. The default for bInsert is false.
submitForm Parameters: cURL, [bFDF], [bEmpty], [aFields], [bGet] Returns: nothing Use this method to submit the form to a specific URL. The first parameter, cURL, is the URL to submit to. This string must end in #FDF if the result from the submission is FDF and the document is being viewed inside a browser window. The optional bFDF parameter is a boolean that indicates to submit as FDF or HTML. If set to true, the default, it submits the form data as FDF. If false, it submits it as HTML (URL encoded). The optional bEmpty parameter is a boolean that indicates, when true, that all fields are submitted, including those that have no value and if false to exclude those that currently have no value. The default for bEmpty is false.
29
The optional aFields parameter is the array of field names to submit or a string containing a single field name. If this parameter is present then only the fields indicated are submitted, except those excluded by parameter bEmpty. If this parameter is omitted or is null then all fields in the Form are submitted (again subject to the restrictions of bEmpty). You can include non-terminal fields in the array or the string passed as a parameter: this is a simple shortcut for having a whole subtree submitted. Example:
/* Submit the form to the server */ this.submitForm("http://myserver/cgi-bin/myscript.cgi#FDF"); /* Or */ this.submitForm("http://myserver/cgi-bin/myscript.cgi#FDF", true, "name");
The example above illustrates a shortcut to submitting a whole subtree. Passing name as part of the field parameter, submits name.title, name.first, name.middle and name.last.
4.0 Addition
The optional bGet parameter indicates, if true, that the submission uses the GET HTTP method and if false (the default) a POST. GET is only allowed if using Acrobat Web Capture to submit (the browser interface only supports POST) and only if the data is sent as HTML (i.e. bFDF should be false).
Note:
You need to be running inside a web browser or have the Acrobat Web Capture plug-in installed, in order to call the submitForm method (unless the URL uses the mailto scheme, in which case it will be honored even if not running inside a web browser, as long as the SendMail plug-in is present).
Note:
30
Event Object
All JavaScripts are executed as the result of a particular event (also referred to as a trigger). Acrobat Forms accepts the following events and executes any scripts that are specified for these events: mouse enter, mouse down, mouse up, mouse exit, keystroke, format, validate, and calculate. It is important to JavaScript writers to know what these events are and when and what order they are processed.
Event Processing
Mouse Enter The mouse enter event is triggered when a user moves the mouse pointer inside the rectangle of a field. This is the typical place to open a text field to display help text, etc.
Mouse Down The mouse down event is triggered when a user starts to click on a form field and the mouse button is still down. It is advised that you perform very little processing (i.e. play a short sound) during this event. A mouse down event will not occur unless a mouse enter event has already occurred.
Mouse Up The mouse up event is triggered when the user clicks on a form field and releases the mouse button. This is the typical place to attach routines such as the submit action if a form. A mouse up event will not occur unless a mouse down event has already occurred.
Mouse Exit The mouse exit event is the opposite of the mouse enter event and occurs when a user moves the mouse pointer outside of the rectangle of a field. A mouse exit event will not occur unless a mouse enter event has already occurred.
Keystroke The keystroke event occurs whenever a user types a keystroke into a text box or combo box (this includes cut and paste operations), or selects an item in a combo box drop down or listbox field. A keystroke script may want to limit the type of keys allowed. For example, a numeric field might only allow numeric characters.
31
The user interface for Acrobat Forms allows the author to specify a Selection Change script for list boxes. The script is triggered every time an item is selected. This is implemented as the keystroke event where the keystroke value is equivalent to the user selection . This behavior is also implemented for the combo box the keystroke could be thought to be a paste into the text field of the value selected from the drop down list. There is a final call to the keystroke script before the validate event is triggered. This call sets the willCommit property to true for the event. With keystroke processing, it is sometimes useful to make a final check on the field value before it is committed (pre-commit). This allows the script writer to gracefully handle particularly complex formats that can only be partially checked on a keystroke by keystroke basis.
Validate Regardless of the field type, user interaction with the field may produce a new value for that field. After the user has either clicked outside a field, tabbed to another field, or pressed the enter key, the user is said to have committed the new data value. The validate event is the first event generated for a field after the value has been committed so that a JavaScript can verify that the value entered was correct. If the validate event is successful, the next event triggered is the calculate event.
Calculate The calculate event causes all fields that have a calculation script attached to them to be executed. All fields that depend on the value of the validated field will now be re-calculated. These fields may in turn generate additional validate, calculate, and format events. Calculated fields may have dependencies on other calculated fields whose values must be determined beforehand. The calculation order array contains an ordered list of all the fields in a document that have a calculation script attached. When a full calculation is needed, each of the fields in the array is calculated in turn starting with the zeroth index of the array and continuing in sequence to the end of the array. To change the calculation order of fields, use the Tools->Forms->JavaScript->Set Calculation Order... menu item in Adobe Acrobat.
Format Once all dependent calculations have been performed the format event is triggered. This event allows the attached JavaScript to change the way that the data value appears to a user (also known as its presentation or appearance). For example, if a data value is a number and the context in which it should be displayed is currency, the formatting script can add a dollar sign ($) to the front of the value and limit it to two decimal places past the decimal point.
32
This property specifies the change in value that the user has just typed. The change is replaceable such that if the JavaScript wishes to substitute certain characters, it may.
4.0
Use this property to determine how a form field lost focus. Valid values are: 0 - value was not committed (e.g. escape key was pressed). 1 - value was committed because of a click outside the field using the mouse. 2 - value was committed because of hitting the enter key. 3 - value was committed by tabbing to a new field. For example, to automatically display an alert dialog after a field has been committed add the following to the fields format script:
if (event.commitKey != 0) app.alert(Thank you for your new field value.);
This property is a boolean that specifies whether the modifier key is down during a particular event. The modifier key on the Microsoft Windows platform is Control and on the Macintosh platform is Option or Command. The modifier property is not supported on UNIX.
This property is used for validation. It indicates whether a particular event in the event chain should succeed. Set rc to false to prevent a change from occurring or a value from committing. By default rc is true.
33
For each event, except the mouse related events, the static event object is populated with the following data. In most events, it is important for JavaScript to set the rc (return code) property to indicate that the event can proceed.
This property specifies the ending position of the current text selection during a keystroke event.
This property specifies the starting position of the current text selection during a keystroke event.
This property is a boolean that specifies whether the shift key is down during a particular event.
This property contains the target object that triggered the event. In all mouse events it is the field object that triggered the event. In other events like page open and close it is the document or this Object.
value Type: Various Event: Validate, Calculate, Format, SelChange Access: R/W
For the validate event, value is the value that the field contains when it is committed. The current field value is the value property for the field. For example, the following JavaScript verifies that the field value is between zero and 100. Example:
if (event.value < 0 || event.value > 100) { app.beep(0);
34
For a calculate event, JavaScript should set this property. This is the value that the field should take upon completion of the event. For example, the following JavaScript sets the calculated value of the field to the value of the SubTotal field plus tax.
var f = this.getField("SubTotal"); event.value = f.value * 1.0725;
For a format event, JavaScript should set this property. This is the value used when generating the appearance for the field. By default, it contains the value that the user has committed. For example, the following JavaScript formats the field as a currency type of field.
event.value = util.printf("$%.2f", event.value);
Use this property to verify the current keystroke event before the data is committed. This is useful to check the target form field values and for example verify if character data instead of numeric data was entered. JavaScript sets this property to true after the last keystroke event and before the field is validated. Example:
var value = event.value if (event.willCommit) // Final value checking. else // Keystroke level checking.
For more examples of using willCommit, refer to the Acrobat Forms JavaScript application (Aform.js) in your Acrobat plug-ins directory.
35
Field Object
The Field object represents an Acrobat form field (that is, a field created using the Acrobat form tool). In the same manner that an author might want to modify an existing fields properties like the border color or font, the Field object gives the JavaScript user the ability to perform the same modifications.
This example allows the script to now manipulate the form field Total via the variable f.
Field Properties
The following is a chart of field property names used by Acrobat with Javascript and the field properties that are available:
Field Property Name Type Text Field Combo Box List Box Push Button Check Box Radio Button Signa ture Read Access Write Access
alignment borderStyle calcOrderIndex charLimit defaultValue delay display doc editable fillColor hidden
String String Integer Integer String boolean Integer Object Boolean Array Boolean
36
Type
Text Field
Combo Box
List Box
Push Button
Check Box
Radio Button
Signa ture
Read Access
Write Access
highlight lineWidth lineWidth name numItems password print readonly required strokeColor style textColor textColor textSize type userName value
String Integer Boolean String Integer Boolean Boolean Boolean Boolean Array String Array String Integer String String Various
This property determines how the text is laid out within the text field. Valid alignments include left, center, and right.
var f = this.getField("MyText"); f.alignment = "center";
37
This property specifies the border style for a field. Valid border styles include solid, dashed, beveled, inset, and underline. The border style determines how the border for the rectangle is drawn. The solid style strokes the entire perimeter of the rectangle with a solid line. The dashed style strokes the perimeter with a dashed line. The beveled style is equivalent to the solid style with an additional beveled (pushed-out appearance) border applied inside the solid border. The inset style is equivalent to the solid style with an additional inset (pushed-in appearance) border applied inside the solid border. The underline style strokes the bottom portion of the rectangles perimeter. The border object is a static convenience constant that defines all the border styles of a field. The following example illustrates how to set the border style of a field to solid:
var f = this.getField("MyField"); f.borderStyle = border.s; /* border.s evaluates to "solid" */
The following chart defines the borderStyle property and its associated keywords:
Type solid beveled dashed inset underline Keyword border.s border.b border.d border.i border.u
Use this property to change the calculation order of fields in the document. When a computable Text or Combo Box field is added to a document, it is added to the end of the document and the fields name is placed in the calculation order array. The calculation order array determines the order fields are calculated in the document (see Event Processing for more information about calculation order arrays). The calcOrderIndex property works similarly to the Calculate tab used by the Acrobat Exchange Form tool. Note the following example:
38
In this example, the this Object method getField, gets the newItem field that was added after oldItem field. It then changes the calcOrderIndex of the oldItem field so that it is calculated before newItem field.
This property limits the number of characters that a user can type into a text field.
This property exposes the default value of a field. This is the value that the field is set to when the form is reset.
This property delays the redrawing of a fields appearance. It is generally used to buffer a series of changes to the properties of the field before requesting that the field regenerate its appearance. Setting the property to true forces the field to wait until delay is set to false. The update of its appearance then takes place, redrawing the field with its latest settings.
// Get the MyCheckBox field var f = this.getField("MyCheckBox"); // set the delay and change the fields properties // to beveled edge and medium thickness line. f.delay = true; f.borderStyle = border.b; f.strokeWidth = 2; // force the changes now f.delay = false;
There is a corresponding document level delay flag if changes are being made to many fields at once.
39
4.0
This property controls whether the field is hidden or visible on screen and in print:
Effect Field is visible on screen and in print Field is hidden on screen and in print Field is visible on screen but doesnt print Field is hidden on screen but prints Keyword display.visible display.hidden display.noPrint display.noView
This property defines the document the field belongs to. Its value is the this Object or the this Object . Please refer to the this Object section for more details.
Combo boxes can be editable, that is, the user can type in a selection. This property determines whether the user can type in a selection or must choose one of the provided selections.
var f = this.getField("MyComboBox"); f.editable = true;
This property specifies the background color for a field. The background color is used to fill the fields rectangle. Values are defined by using transparent, gray, RGB or CMYK color. Refer to the Global Object section for information on defining color arrays and how values are used with this property.
var f = this.getField("MyField"); if (color.equal(f.fillColor, color.red))
40
In older versions of this specification, this property was named bgColor. The use of bgColor is now discouraged but for backwards compatibility is still valid.
This property controls whether the field is hidden or visible to the user. If the value is false the field is visible, true the field is invisible. The default value for hidden is false.
// Set the field to hidden var f = this.getField("MyField"); f.hidden = true;
See also the display property which supersedes this property in later versions.
This property defines how a button reacts when a user clicks it. The four highlight modes supported are none, invert, push and outline. The none highlight does not indicate visually that the button has been clicked. The invert highlight causes the region encompassing the buttons rectangle to invert momentarily. The push highlight displays the down face for the button (if any) momentarily. The outline highlight causes the border of the rectangle to invert momentarily. The highlight object defines all the characteristics that a button can have. Use it in your scripts to access the highlight of choice. The following chart shows the highlight object and its associated keywords:
Type none invert push outline Keyword highlight.n highlight.i highlight.p highlight.o
41
This property specifies the thickness of the border when stroking the perimeter of a fields rectangle. If the stroke color is transparent, this parameter has no effect except in the case of a beveled border. You can set the lineWidth property in JavaScript by using the integer values below:
Line Width none thin medium thick Key Value 0 1 2 3
For example:
// Change the border width of the Text Box to medium thickness f.lineWidth = 2
The default value for lineWidth is 1 (thin). Any integer value can be used. However, values beyond 5 may distort the fields appearance. In older versions of this specification, this property was borderWidth. The use of borderWidth is now discouraged but for backwards compatibility is still valid.
This read-only property determines how the text is wrapped within the field. Text fields can be single line (clip to field boundaries) or multi-line (wrap to field boundaries).
42
This property allows you to access the fully qualified field name of the field as a string object.
var f = this.getField("MyField"); console.println(f.name);
This property causes the field to display asterisks for the data entered into the field. Upon submission, the actual data entered is sent. Fields that have the password attribute set will not have the data in the field saved when the document is saved to disk.
This property determines whether a given field prints or not. Set the print property to true to allow the field to appear when the user prints the document, set it to false to prevent printing. This property can be used to hide control buttons and other fields that are not useful on the printed page.
var f = this.getField("MyField"); f.print = false;
This property has been superseded by the display property and its use is discouraged.
This property sets or gets the read-only characteristic of a field. If a field is read-only, the user can see the field but cannot change it.
43
This property sets or gets the required characteristic of a field. If a field is required its value must be non-null when the user clicks a submit button that causes the value of the field to be posted. If the field value is null, the user receives a warning message and the submit does not occur.
var f = this.getField("MyField"); f.required = true;
This property specifies the stroke color for a field which is used to stroke the fields rectangle with a line as large as the line width. Values are defined by using transparent, gray, RGB or CMYK color. Refer to the Color Arrays section for information on defining color arrays and how values are used with this property. In older versions of this specification, this property was borderColor. The use of borderColor is now discouraged but for backwards compatibility is still valid.
This property allows the user to set the style of a check box or a radio button, that is, sets the glyph used to indicate that the check box or radio button has been selected. Valid styles include check, cross, diamond, circle, star, and square. The following defines the style properties and the associated keywords:
Style check cross diamond circle star square Keyword style.ch style.cr style.di style.ci style.st style.sq
The following example illustrates the use if this property and the style object:
var f = this.getField("MyCheckbox"); f.style = style.ci;
44
This property determines the foreground color of a field. It represents the text color for text, button, or list box fields and the check color for check box or radio button fields. Values are defined the same as the fillColor property. Refer to the Color Arrays section for information on defining color arrays and how values are set and used with this property.
var f = this.getField("MyField"); f.textColor = color.red;
In older versions of this specification, this property was fgColor. The use of fgColor is now discouraged but for backwards compatibility is still valid.
textFont Type: String Fields: Text, Combo, List & Button Access: R/W
The textFont property determines the font that is used when laying out text in a text field, combo box, list box or button. Valid fonts are defined as properties of the font object as follows:
Text Font Times-Roman Times-Bold Times-Italic Times-BoldItalic Helvetica Helvetica-Bold Helvetica-Oblique Helvetica-BoldOblique Courier Courier-Bold Courier-Oblique Courier-BoldOblique Symbol ZapfDingbats Keyword font.Times font.TimesB font.TimesI font.TimesBI font.Helv font.HelvB font.HelvI font.HelvBI font.Cour font.CourB font.CourI font.CourBI font.Symbol font.ZapfD
45
The following example illustrates the use of this property and the font object.
// set the font of MyField to Helvetica var f = this.getField("MyField"); f.textFont = font.Helv;
This property determines the text size in points that is used in all controls. In combo box and radio button fields, the text size determines the size of the check. Valid text sizes include zero and the range from 4 to 144 inclusive. A text size of zero means that the largest point size that can still fit in the fields rectangle should be used (in multi-line text fields and buttons this is always 12 point).
// set the text size of MyField to 28 point var f = this.getField("MyField"); f.textSize = 28;
This read-only property returns the type of the field as a string. Valid types that are returned include button, checkbox, combobox, listbox, radiobutton, and signature.
This property returns/sets the user name of the field (short description) as a string. The user name is intended to be used as tool tip text whenever the mouse cursor enters a field. It can also be used as a user friendly name when generating error messages instead of the field name (which can sometimes not be suitable for human consumption).
This property gets the value of the field data that the user has entered. Depending on the type of the field, the value may be a string, date, or number. Typically, the value is used to create calculated fields.
var oil = this.getField("Oil");
46
In this example, the value of the field being calculated is set to the sum of the oil and filter fields and multiplied by the state sales tax. Value is perhaps the most important of all the field properties.
Field Methods
buttonImportIcon Parameter: none Returns: nothing This method imports the appearance of a button from another PDF file. It prompts the user to select a PDF file available on the system.
clearItems Parameters: none Returns: nothing This method clears all the values in a list box or combo box.
// Clear the field MyListbox var f = this.getField("MyListBox"); f.clearItems();
4.0
This function deletes an item in a combo box or a list box. The parameter nIndex is the index of the item in the list to delete (zero-based). If nIndex is not specified then the currently selected item is deleted.
var a = this.getField("MyListBox"); a.deleteItemAt();
47
This function returns an array of terminal children fields (i.e. fields that can have a value) for a parent field. This method can be particularly useful for doing field calculations in tables where a parent field value is the sum of all of its children. To understand more about field name and hierarchies, please see the section on Field Properties.
// f has 3 children: f.v1, f.v2, f.v3 var f = this.getField("f"); var a = f.getArray(); var v = 0.0; for (j =0; j < a.length; j++) v += a[j].value; // v contains the sum of all the children of field "f"
getItemAt Parameters: nIndex Returns: internal value in an item in a list or combo box This function gets the internal value of an item in a combo box or a list box. The parameter nIndex is the index of the item in the list to obtain. If nIndex is set to -1, it returns the value of the last item in the list. The getItemAt function returns the exported or internal value of the item at nIndex in the combo box or list box.
// returns value of first item in list l var a = this.getField("MyListBox"); var v = a.getItemAt(0);
insertItemAt Parameters: cName, cExportValue, [nIndex] Returns: nothing This function inserts a new item into a combo box or a list box. cName is the index at which to insert the item in a list box or combo box. cExportValue is the string export value of the item i.e. internal value of the item being inserted. nIndex is the index in the list to insert the item at. If nIndex is 0, cName is inserted at the top of the list. If nIndex is 1, cName is inserted at the end of the list. The default value for nIndex is 0.
var l = this.getField("l"); /* l is a list box */ var v =l.insertItemAt("sam", "s", 0); /* inserts sam to top of list l */
4.0
48
Returns: nothing This method sets the list of items for a combo box or a list box. The single parameter necessary to call this method must be an array. Each element in the array must either be an object convertible to a string or another array. If the element can be converted to a string, the user and export values for the list item are equal to the string. If the element is an array it must consist of two sub-elements. The first sub-element should be convertible to a string which will be used as the user value, the second element will be used as the export value.
var l = this.getField("ListBox"); l.setItems(["One", "Two", "Three"]); var c = this.getField("StateBox"); c.setItems([["California", "CA"],["Massachusetts", "MA"],["Arizona", "AZ"]]); var c = this.getField("NumberBox"); c.setItems(["1", 2, 3, ["PI", Math.PI]]);
49
Global Object
The Global object is a static JavaScript object that allows you to share data between documents and have data be persistent across sessions. This is referred to as persistent global data. Global data-sharing and notification across documents is done through a publish and subscribe mechanism. This mechanism gives you the ability to monitor global data variables and report their value changes across documents. Global data can be specified by adding properties to the global object. The property type can be a string, a boolean, or a number. For example, to add a variable called volume and to allow all document scripts to have access to this variable, a script would simply define it as:
global.volume = 80;
To delete a variable or a property from the global object, use the delete operator to remove the defined property. For more information on the reserved JavaScript keyword delete, please see Netscapes JavaScript Reference Manual. For example, to remove the property volume from the global object, call the following script:
delete global.volume
Note:
Persistent global data only applies to variables of type boolean, number or string. For all persistent data there is a 32k limit for the maximum size of the global persistent variables. Any data added to the string after the 32k limit will be dropped.
It is recommended that JavaScript developers building scripts for Acrobat Forms, utilize some type of naming convention when specifying persistent global variables. One suggestion is to start all variables with your company name. For example, if your company name is Xyz, start
50
all variables with xyz_. This will prevent collisions with other persistent global variable names throughout the documents. Note that global variables that are persistent are recorded in the plug-in level glob.js file upon application exit and re-loaded at application start. See the section on Plug-in folder level scripts for more details.
51
this Object
In JavaScript the special keyword this refers to the current object. In Acrobat Forms the current object is defined as follows: In an object method, it is the object to which the method belongs. In a constructor function, it is the object being constructed. In a function defined at the Plug-in folder level it is undefined. It is recommended that calling functions pass the document object to any function at this level that needs it. In a Document level script or Field level script it is the document object and therefore can be used to set or get document properties and functions. For example, assume that the following function was defined at the Plug-in folder level:
function PrintPageNum(doc) { /* Print the current page number to the console. */ console.println(Page= + doc.page); }
The following script outputs the current page number to the console (twice) and then prints the page:
PrintPageNum(this); /* Must pass the document object. */ console.println(Page= + this.pageNum); /* Same as the previous call. */ this.print(false, this.pageNum, this.pageNum); /* Prints the current page. */
is equivalent to
this.f = this.getField(Hello);
with the exception that the variable f can be garbage collected at any time after the script is run. If a script uses a name that conflicts with a document level property or method and the this object is the current document then a run-time error will result: Invalid or unknown property, set not possible. The following script fragment will generate such an error:
var pageNum = this.pageNum;
To avoid such an error, rename your variables and functions to avoid conflict:
var pNum = this.pageNum;
52
Util Object
The Util Object is a static JavaScript object that defines a number of utility methods and convenience functions for string and date formatting.
printx Parameters: cMask, Returns: cResult This method formats a source string according to a masking string. Valid masking values are as follows:
Value ? X A 9 * \ > < = Effect Copy next character. Copy next alphanumeric character, skipping any others. Copy next alpha character, skipping any others. Copy next numeric character, skipping any others. Copy the rest of the source string from this point on. Escape character. Uppercase translation until further notice. Lowercase translation until further notice. Preserve case until further notice (default).
To format a string as a U.S. telephone number, for example, use the following script:
var v = "aaa14159697489zzz"; v = util.printx("9 (999) 999-9999", v); console.println(v);
53
printd Parameters: cFormat, date Returns: cResult Use this method to format a date according to a format string. Valid string format values are as follows:
String mmmm mmm mm m dddd ddd dd d yyyy yy HH H hh h MM M ss s tt t \ Effect Long month Abbreviated month Numeric month with leading zero Numeric month without leading zero Long day Abbreviated day Numeric date with leading zero Numeric date without leading zero Long year Abbreviate Year 24 hour time with leading zero 24 hour time without leading zero 12 hour time with leading zero 12 hour time without leading zero minutes with leading zero minutes without leading zero seconds with leading zero seconds without leading zero am/pm indication single digit am/pm indication use as an escape character Example September Sept 09 9 Wednesday Wed 03 3 1997 97 09 9 09 9 08 8 05 5 am a
To format the current date in long format, for example, you would use the following script:
var d = new Date(); console.println(util.printd("mmmm dd, yyyy", d));
54
4.0
This method converts the supplied date, cDate, into a JavaScript date object according to rules of the supplied format string, cFormat. cFormat uses the same syntax as found in printd. This routine is much more flexible than using the date constructor directly.
/* Turn the current date into a string. */ var cDate = util.printd("mm/dd/yyyy", new Date()); console.println("Todays date: " + cDate); /* Parse it back into a date. */ var d = util.scand("mm/dd/yyyy", cDate); /* Output it in reverse order. */ console.println("Yet again: " + util.printd("yyyy mmm dd", d));
Note:
Given a two digit year for input, scand resolves the ambiguity as follows: if the year is less than 50 then it is assumed to be in the 21st century (i.e. add 2000), if it is greater than or equal to 50 then it is in the 20th century (add 1900). This heuristic is often known as the Date Horizon.
55
Implementation Considerations
JavaScript Locations and Loading
JavaScripts work with Acrobat Forms on a variety of levels: the plug-in level, document level, and field level. These levels restrict the type of processing that can occur and are loaded at different times.
4.0 If the file Config.js is present this file can be used to customize the look of the viewer
by removing toolbar buttons and menu items (see the application methods hideMenuItem and hideToolbarButton). The plug-in level scripts are loaded in the following order: Config.js (if it exists), AFString.js, AForm.js, glob.js (if it exists), and then all other .js files in no particular order.
Document level
By using the Adobe Acrobat menu item Tools->Forms->Document Scripts, the user can add, modify, or delete document level scripts. These scripts should be function definitions that are generally useful to the document but are not applicable outside the document. Document level scripts are executed after the document has opened and after the plug-in level scripts are loaded. Document level scripts are stored within the PDF document. Therefore, the forms programmer should make every effort to package scripts as effectively as possible.
56
Field level
The user can add scripts to a form field definition using a dialog box in the form editing tool. (see Event Processing section below). These scripts are executed as the events occur (e.g. mouse up or calculate). Scripts that are field specific should be created at this level. Usually these scripts validate, format, or calculate field values. Unlike plug-in folder scripts, document level and field level scripts are stored within the PDF document and therefore the forms programmer should make every effort to package his scripts as effectively as possible (e.g. code reuse) at the various levels for performance and file size reasons.
Form Field Hierarchies with JavaScript Using our original flat names FirstName, MiddleName and LastName, imagine that we want to change the background color of these fields to yellow (to indicate missing data, or emphasize an important point). We would need two lines of JavaScript code for each field:
var name = this.getField("FirstName"); name.fillColor = color.yellow; name = this.getField("MiddleName"); name.fillColor = color.yellow; name = this.getField("LastName"); name.fillColor = color.yellow;
With our hierarchy of Name.First, Name.Middle and Name.Last above (and perhaps, Name.Title if used), we can change the background color of these fields with just two lines of code instead of six:
57
When using this hierarchy within a JavaScript, remember you can only change appearance related properties of the parent field and that appearance changes propagate to all children. You cannot change the fields value. For example if you try the following script:
var name = this.getField("Name"); name.value = "Lincoln";
the script will fail. Name is considered a parent field. You can only change the value of terminal fields (i.e. a field that does not have children like Last or First). The following script executes correctly:
var first = this.getField("Name.First"); var last = this.getField("Name.Last"); first.value = "Abraham"; last.value = "Lincoln";
Note:
All date manipulations in JavaScript, including those methods that have been documented in this specification are Year 2000 (Y2K) compliant.
Converting a Date to a String Acrobat Forms provides several date related methods in addition to the ones provided by the JavaScript Date object. These methods are the preferred method of converting between Date objects and strings. Because of Acrobat Forms' ability to handle dates in many formats, the Date object does not always handle these conversions correctly. To convert a Date object into a string, the printd method of the Util Object is used. Unlike the built-in conversion of the Date object to a string, printd allows an exact specification of how the date should be formatted.
/* Example of util.printd */ var d = new Date(); /* Create a Date object containing the current date. */ /* Create some strings from the Date object with various formats with ** util.printd */ var s1 = util.printd("mm/dd/yy", d);
58
var s2 = util.printd("yy/m/d", d); var s3 = util.printd("mmmm dd, yyyy", d); var s4 = util.printd("dd-mmm-yyyy", d); /* print these strings to the console */ console.println("Format mm/dd/yy looks like: " + s1); console.println("Format yy/m/d looks like: " + s2); console.println("Format mmmm dd, yyyy looks like: " + s3); console.println("Format dd-mmm-yyyy looks like: " + s4);
Note:
Given the relative closeness of the new millenium and the ever increasing length of the human lifespan, it is advised to output dates with a four digit year to avoid ambiguity.
Converting a String to a Date To convert a string into a Date object the scand method of the Util Object, is used. It accepts a format string that it uses as a hint as to the order of the year, month, and day in the input string.
/* Example of util.scand */ /* Create some strings containing the same date in differing formats. */ var s1 = "03/12/97"; var s2 = "80/06/01"; var s3 = "December 6, 1948"; var s4 = "Saturday 04/11/76"; var s5 = "Tue. 02/01/30"; var s6 = "Friday, Jan. the 15th, 1999"; /* Convert the strings into Date objects using util.scand */ var d1 = util.scand("mm/dd/yy", s1); var d2 = util.scand("yy/mm/dd", s2); var d3 = util.scand("mmmm dd, yyyy", s3); var d4 = util.scand("mm/dd/yy", s4); var d5 = util.scand("yy/mm/dd", s5); var d6 = util.scand("mmmm dd, yyyy", s6); /* Print the dates to the console using util.printd */ console.println(util.printd("mm/dd/yyyy", d1)); console.println(util.printd("mm/dd/yyyy", d2)); console.println(util.printd("mm/dd/yyyy", d3));
59
Unlike the date constructor (new Date(...)), scand is rather forgiving in terms of the string passed to it.
Note:
Given a two digit year for input, scand resolves the ambiguity as follows: if the year is less than 50 then it is assumed to be in the 21st century (i.e. add 2000), if it is greater than or equal to 50 then it is in the 20th century (add 1900). This heuristic is often known as the Date Horizon.
Date Arithmetic It is often useful to do arithmetic on dates to determine things like the time interval between two dates or what the date will be several days or weeks in the future. The JavaScript Date object provides several ways to do this. The simplest and possibly most easily understood method is by manipulating dates in terms of their numeric representation. Internally, JavaScript dates are stored as the number of milliseconds (one thousand milliseconds is one whole second) since a fixed date and time. This number can be retrieved through the valueOf method of the Date object. The Date constructor allows the construction of a new date from this number.
/* Example of date arithmetic. */ /* Create a Date object with a definite date. */ var d1 = util.scand("mm/dd/yy", "4/11/76"); /* Create a date object containing the current date. */ var d2 = new Date(); /* Number of seconds difference. */ var diff = (d2.valueOf() - d1.valueOf()) / 1000; /* Print some interesting stuff to the console. */ console.println("It has been " + diff + " seconds since 4/11/1976"); console.println("It has been " + diff / 60 + " minutes since 4/11/1976"); console.println("It has been " + (diff / 60) / 60 + " hours since 4/11/1976"); console.println("It has been " +
60
((diff / 60) / 60) / 24 + " days since 4/11/1976"); console.println("It has been " + (((diff / 60) / 60) / 24) / 365 + " years since 4/11/1976");
Restricting Access If the author desires to restrict access to the form in its entirety then the standard security model in Acrobat can be selected and an open password defined that requires a user to type in a password before opening the form. Other security handlers exist and are provided by third party developers as plug-ins and may also be useful. E.g. using a public/private key
61
infrastructure to lock a form for a particular set of people or allowing a form to expire after a certain time period. The ability to set a user password is accessed using the Save As function by choosing the appropriate security handler and configuring its settings.
Restricting Permissions The standard security model in Acrobat is accessible at document save time and allows you to set the following restrictions on the document: printing, changing the document, selecting text and graphics, and adding and changing annotations and form fields. Once a form has been authored it is often useful to lock the form so that it may be filled in but cannot be tampered with using the forms tool. For example, after authoring a form may be posted on a Web site. In order to preserve the form integrity it needs to be shielded from any changes to its formulae or internal data routines. If the changing the document restriction is selected, the user can fill-in form fields and add annotations but cannot author or modify form fields or change the background text using the TouchUp plug-in.
In addition, once a form has been filled in, it is often desirable to lock the entire document so that it cannot be changed whatsoever. In filling out a tax or other sensitive form, the user may wish to save the document so that no further changes to the document are allowed. In order to disallow both fill-in and authoring, the changing the document and the adding and changing annotations and form fields restrictions must be selected.
Digital Signatures Although these form fields do not restrict access or permissions, they do allow an author or user to verify that a document has not been changed after a signature has been applied. An author may digitally sign a form thus signifying that it has been released for fill-in. A user can verify the signature to make sure that the form has not been tampered with and is thus
62
official. A blind signature (signed without any appearance) is often useful in this situation and can be created via the pull right menu in the signatures pane. After fill-in a user can also sign the document either by using the signing tool or filling in a pre-authored signature field, thus ensuring that the form undergoes no further changes without detection.
4.0
Signature fields allow the user to digitally sign a document. Once a signature is applied to the document any subsequent changes to the document will cause the signature to indicate that the Document has been changed after signing. A signature fields value is read-only. An unsigned signature has a null value. Once the field has been signed its value is non-null. When crafting a custom script for when the signature field is signed remember to allow for resetting the form (i.e. the fields value is set to null). For example, imagine a form where upon signing a signature field that all fields whose names starts with A are locked and all fields whose names start with B are locked. We might start with a script fragment, to be executed at signature time, looking something like this:
/* This example is incorrect. */ var f = this.getField("A"); /* Lock all A fields. */ f.readOnly = true; f = this.getField("B"); /* Unlock all B fields. */ f.readOnly = false;
This is a typical operation for many forms. This script is incorrect and when the form is reset it will lock and unlock the wrong fields. Instead, it should check the value of the signing event and react accordingly:
var bLock = (event.value != ""); var f = this.getField("A"); /* Lock A on sign, unlock on reset. */ f.readOnly = bLock; f = this.getField("B"); /* Unlock B on sign, lock on reset. */ f.readOnly = !bLock;
There is a convenience routine available for your use called AFSignatureLock() in AForm.js (see JavaScript Locations and Loading) that performs the programmatic equivalent of the simple locking user interface in the signature properties dialog. This allows you to easily lock and unlock all fields, a particular list of fields, or all fields but those specified. The example is recoded using this convenience routine below:
var bLock = (event.value != ""); AFSignatureLock(this, "THESE", "A", bLock);
63
64