Summary of Contents for Adobe 12001196 - Acrobat - Mac
Page 1
Acrobat JavaScript Scripting Guide Technical Note #5430 Version: Acrobat 6.0 ADOBE SYSTEMS INCORPORATED Corporate Headquarters 345 Park Avenue San Jose, CA 95110-2704 (408) 536-6000 http://partners.adobe.com May 2003...
Page 2
Adobe Systems Incorporated. PostScript is a registered trademark of Adobe Systems Incorporated. All instances of the name PostScript in the text are references to the PostScript language as defined by Adobe Systems Incorporated unless otherwise stated. The name PostScript also is used as a product trademark for Adobe Systems’...
Page 6
Contents Restricting Permissions ....... . . 81 Digital Signatures ........81 How can I make restricted Acrobat JavaScript methods available to users? .
Preface Introduction Welcome to the Adobe Acrobat JavaScript Scripting Guide . This scripting guide is designed to give you an overview of how you can use the Acobe Acrobat 6 Pro JavaScript development environment to develop and enhance Acrobat applications.
Preface How To Use This Guide After reading this guide and completing the exercises, you should be equipped to start using Acrobat JavaScript. During the development process, you’ll likely find yourself reviewing the content of this guide, as well as exploring additional, more in-depth information that updates to this guide offer in key technical areas.
Placeholders in code AFSimple_Calculate( cFunction , examples cFields ) blue Live links to Web pages The Acrobat Solutions Network URL is: http://partners/adobe.com/asn/ Live links to sections Using the SDK. within this document Live links to other See the Acrobat Core API Overview...
SDK. If, for some reason, you did not install the entire SDK and you do not have all the documents, please visit Adobe Solutions Network Web site to find the documents you need. Then install them in the appropriate directories. You can use the Acrobat SDK Documentation Roadmap located at the beginning of this document as a guide.
However, Acrobat provides far more capabilities than a simple document viewer. You can enhance an Adobe Portable Document Format (PDF) document so that it contains fields to capture user-entered data as well as buttons to initiate user actions. This type of...
PDF files. Acrobat also contains functionality to support online team review. Documents that are ready for review are converted to Adobe PDF. When a reviewer views an Adobe PDF document in Acrobat and adds comments to it, those comments (or annotations) constitute an additional layer of information on top of the base document.
Acrobat JavaScript enables you to do a wide variety of things within a PDF document. The Adobe Solutions Network (ASN) has an Adobe Acrobat JavaScript Training course that covers a wide variety of the possibilities available within Acrobat JavaScript. This course material is in a PDF file available at: http://partners.adobe.com/asn/developer/training/acrobat/javascript/main.html...
Page 14
“Integrating with a Database, ” for details. Setting the comment repository preference If you plan on using Adobe Acrobat’s collaborative review capabilities, you need to specify the type of comment repository to use, as well as its location. These are referred to as comment repository preferences.
By interacting with the App object, you can get to all of the currently open PDF documents and customize Acrobat by adding menus and menu items. You can also query App to determine which type of Adobe product (for example, Reader, Approval, or full Acrobat) and which version the end user is using.
The Console object is a static object to access the JavaScript console for displaying debug messages and executing JavaScript. It does not function in the Adobe Reader or Acrobat Standard. Use the Console object as a debugging aid and as a means of interactively testing code.
Introduction to Acrobat JavaScript Acrobat JavaScript Object Overview see the ASN JavaScript training module on “Location Matters” and the ASN JavaScript training module on “Batch Processing with Sequences. ” Util The Util object is a static JavaScript object that defines a number of utility methods and convenience functions for string and date formatting and parsing.
Acrobat JavaScript Editor and Debugger Console Introduction to the JavaScript Editor and Debugger Console Acrobat provides a development environment in which you can implement and test Acrobat JavaScript functionality. On both Windows and Macintosh systems, you have a choice of using Acrobat’s built-in editor or a third-party editor to develop your code. To introduce you to a simple method of evaluating short scripts, this chapter details how you can use Acrobat’s JavaScript debugger console with the built-in JavaScript editor to evaluate scripts.
Acrobat JavaScript Editor and Debugger Console JavaScript Console JavaScript Console The Acrobat JavaScript console provides an interface for testing and debugging your JavaScript code. It is editable and interactive. The console is also handy for experimenting with object properties and methods before you use them in your code. You can use the console as an editor and interactively execute lines or blocks of code within the console.
Acrobat JavaScript Editor and Debugger Console Using a JavaScript Editor To move the cursor four spaces to the left, press Shift+Tab. (This moves the cursor to the beginning of the line if it is fewer than four spaces from the left.) To move a whole line or block of code to the right four spaces, highlight the code, or a portion of a line, then press Tab.
Page 22
Acrobat JavaScript Editor and Debugger Console Using a JavaScript Editor 5. Click Add to open the JavaScript editor. 6. In the editor window, write the JavaScript script that you want to run when the user opens the page. 7. When you are done, click Close to close the editor. If there are errors in your code, the JavaScript editor will highlight the code line in question and display an error message, as shown in Figure...
Acrobat JavaScript Editor and Debugger Console Specifying the Default JavaScript Editor Specifying the Default JavaScript Editor You can choose to either use the built-in JavaScript editor that comes with Acrobat, or an external JavaScript editor of your choice. To set the default JavaScript editor that you want to use: 1.
Acrobat JavaScript Editor and Debugger Console Using the Built-in Acrobat JavaScript Editor 4. Click OK to close the Preferences dialog box. Using the Built-in Acrobat JavaScript Editor You can use the built-in Acrobat JavaScript editor to evaluate JavaScript code, just as you use the Acrobat JavaScript console.
Acrobat JavaScript Editor and Debugger Console Using an External Editor Edit > Preferences > JavaScript dialog. This ensures that your editing work is not discarded. If your editor accepts a starting line number on the command line, Acrobat also supports the option of starting the editor on a line that contains a syntax error by making the line number available as a parameter (%n) to insert in the command line.
Acrobat JavaScript Editor and Debugger Console Using an External Editor When Acrobat needs to open the JavaScript editor, it makes the appropriate substitutions in the command line and executes it with the operating sytem shell. In the above case, if the syntax error were on line 43, the command line generated would be something like: "C:\Program Files\vslick\win\vs.exe"...
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console Saving and Closing a File with a Syntax Error If you save and close a file you have been editing and it contains a syntax error (on line 123, for example), Acrobat displays a dialog box with the following message prompting whether you want to fix the error: There is a JavaScript error at line 123.
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console Enabling the Interactive JavaScript Console The console window is part of the JavaScript debugger. To enable the console, you must enable the debugger. 1. In the Preferences dialog, select Enable JavaScript Debugger after Acrobat is restarted from the JavaScript Debugger options.
Page 29
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console 3. Click the Clear button (trash can icon) just below the console window to delete any contents that appear in the window. 4. Type the following code into the console: var myNumber = 1776;...
Page 30
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console Evaluating myNumber IGURE 7. Now evaluate the following line of code by typing it in below the existing console contents and pressing Enter with the cursor positioned on the code to be evaluated: console.println("\n\nThe value of myNumber is "...
Page 31
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console Evaluating a code line IGURE The console.println() method can be very useful to include in your JavaScript code to print debugging information and other messages to the console. It prints the text that you specify and then returns undefined.
Page 32
Acrobat JavaScript Editor and Debugger Console Exercise: Working with the JavaScript Console Acrobat JavaScript Scripting Guide...
Acrobat JavaScript Debugger Introduction to the Acrobat JavaScript Debugger The Acrobat JavaScript Debugger allows debugging of JavaScript code in Acrobat. It is a fully capable JavaScript debugger which lets you set breakpoints and inspect variable values while stepping through code. The debugger is not available in the Acrobat Reader. Debugging is controlled with a single dialog that you can open from the Acrobat menu item Advanced >...
Acrobat JavaScript Debugger Enabling the Acrobat JavaScript Debugger Topics and Exercises Inspect Details Window Starting the Debugger Exercise: Calculator Known Issues Enabling the Acrobat JavaScript Debugger Before you can use the debugger, both JavaScript and the debugger must be enabled. Use the Edit >...
Page 35
Acrobat JavaScript Debugger Enabling the Acrobat JavaScript Debugger Figure 3.1 shows typical JavaScript debugger option settings. Each of the options is described in Table 3.1. JavaScript debugger options ABLE Option Meaning Enable Javascript To enable the debugger you must check this option. The debugger after debugger features such as setting breakpoints become available Acrobat is restarted...
Acrobat JavaScript Debugger Debugger Dialog Window Debugger Dialog Window You can open the debugger dialog window without having a script to debug by using the Acrobat menu item Advanced > JavaScript > Debugger. Familiarize yourself with the parts of the window and the controls as described here before you attempt interactive debugging of a script.
Acrobat JavaScript Debugger Debugger Buttons Debugger dialog IGURE Debugger Buttons The Acrobat JavaScript Debugger allows you to easily control what portions of the script you want to see executed. You can start the debugger using any of the ways described in “Starting the Debugger”...
Acrobat JavaScript Debugger Debugger Buttons Debugger buttons IGURE Resume Interrupt Quit Step Into Step Out Step Over Debugger buttons summary ABLE Button Description Resume Execution Runs a script stopped in the debugger. Interrupt Halts execution. Quit Terminates script execution and closes the debugger dialog. Step Over Single steps through instructions but does not enter function calls encountered.
Acrobat JavaScript Debugger Debugger Buttons Quit The Quit button terminates the debugging session and closes the debugger dialog window. Step Over The Step Over button single-steps through instructions. Clicking Step Over at a function call executes the entire function in a single step rather than executing the function’s instructions one at a time with each click of the button.
Acrobat JavaScript Debugger Debugger Scripts Window Debugger Scripts Window Scripts are automatically collected from a PDF file open in Acrobat when you open the debugger dialog. The debugger displays these in the Scripts window. Figure 3.5 shows an example. Scripts window IGURE Accessing Scripts in the Scripts Window To access scripts you want to display, you click the triangle next to an entry in the Scripts...
Acrobat JavaScript Debugger Call Stack List Scripts inside PDF files ABLE Location Access Document actions Advanced > JavaScript > Set Document Actions Page actions Click the page on the Pages tab; select Options > Page Properties Forms Double-click the form object in form editing mode (see below) to bring up the Form Properties dialog Bookmarks Click the bookmark on the Bookmarks tab;...
Acrobat JavaScript Debugger Inspect Details Window entry represents a function call, or frame, in the stack. The text of an entry displays the line number of the function in the script and the function’s name. The most recent stack frame is the top of the stack and is displayed at the top of the Call Stack drop-down list.
Acrobat JavaScript Debugger Inspect Details Window Inspect details window button controls IGURE Edit New Delete Inspecting Variables The capability of inspecting variables is a powerful tool that you can use to examine the current state of JavaScript objects and variables. It enables you to see the values for variables in the current stack frame, or local scope, being debugged.
Acrobat JavaScript Debugger Inspect Details Window Watches The Watches list enables you to customize your inspection of variables. Watches are JavaScript expressions evaluated every time the debugger stops at a breakpoint or a step in execution. You can add as many watches as you need in the Watches list. You can edit, add, or delete watches using the three buttons just below the Inspect details window.
Page 45
Acrobat JavaScript Debugger Inspect Details Window display an alert telling you that you cannot set a breakpoint on that location. You can only set a breakpoint next to the codeline containing the left curly brace. Figure 3.9, you can set the breakpoint on the line with the left curly brace following the function name callMe().
Acrobat JavaScript Debugger Starting the Debugger Starting the Debugger You can start the debugger in four ways. Two of these ways allow you to debug from the start of execution. The other two allow you to start debugging from an arbitrary point in the script.
Acrobat JavaScript Debugger Stepping Through Your Code Stepping Through Your Code The Acrobat JavaScript Debugger allows you to easily control what portions of the script you want to see executed. Four of the toolbar buttons allow you to step through your code when a script is stopped in the debugger.
Acrobat JavaScript Debugger Exercise: Calculator – Step Into – Step Out – Quit Calculator Calc.pdf uses document-level and form field-level scripts to create the behavior of a simple calculator. The key pad consists of numeric and function keys, the period (.), the equals sign (=), as well as Cancel and Cancel Entry keys.
Acrobat JavaScript Debugger Exercise: Calculator causes a subsequent value entered (to the right of the point) to be divided by 10 to represent the tenths position. Testing the Calculator To familiarize yourself with the basic calculator operation, open Calc.pdf in Acrobat. Experiment with entering expressions and evaluating their results.
Acrobat JavaScript Debugger Exercise: Calculator 5. Summarize your findings. From the above, note that: – Button values display correctly. Clicking 9 displays 9, clicking 3 displays 3, and so forth in the Display field. – Function strings display correctly in the Func field. Clicking *, -, +, and so forth displays the correct function string.
Acrobat JavaScript Debugger Exercise: Calculator 3.10 The value of accum is not updated IGURE Another runtime error 1. Enter 9 + 3 = The result of evaluation is 3. This is indicates another runtime error. 2. If you didn’t delete your watches from the previous session, you can reuse them. For each watch, select the watch in the Inspect details window.
Acrobat JavaScript Debugger Known Issues 3.11 Second Runtime Error IGURE Known Issues Due to some limitations in the JavaScript Debugger, debugging of certain classes of scripts in Acrobat is disabled or unavailable. Fortunately, there are plenty of other places and situations where scripts can be debugged, so that your script can be tested and then transported to its definitive place in case debugging is unavailable.
Acrobat JavaScript Debugger Summary The events DocWillPrint and DocDidPrint cannot be debugged because the printing progress bar conflicts with the debugger. Press the Escape key to clear this situation. Debug scripts using different event triggers and then change the trigger to the required event. Debugging scripts in Acrobat from inside a browser (IE, NS) has some limitations.
Using Acrobat JavaScript in Forms Creating simple JavaScripts There are a number of simple JavaScripts you can integrate into your forms to enhance their interactive capabilities. The scripts described here are commonly used with Acrobat forms. Trying out these scripts in the forms you create will give you a glimpse of what JavaScript offers.
Using Acrobat JavaScript in Forms Creating simple JavaScripts 4. Delete the automatically generated text, defining a Today function, that is displayed in the script window. Type in the following text in the exact format (line wraps are OK) and click OK. var f = this.getField("Today");...
Using Acrobat JavaScript in Forms Creating simple JavaScripts 12.•Click Close in the Text Field Properties dialog. In Acrobat 5 you would have had to explicitly get each field from the this object and use the value properties of each field object, as in the following example (equivalent to the symplified syntax in step 10, above): "...
Using Acrobat JavaScript in Forms Creating simple JavaScripts 3. Click the Actions tab, choose Mouse Up, and then click Add. 4. Choose JavaScript from the Type menu, and then click Edit. 5. To specify go to the next page when the button is selected, in the script window, type in the following text in the exact format, and click OK: this.pageNum++;...
Using Acrobat JavaScript in Forms Creating simple JavaScripts 5. To mail the PDF document to the specified e-mail address when the button is selected, in the script window, enter the following text in the exact format, and click OK: " "...
3. Select JavaScript as the action. For information about selecting an action for a form field, link, bookmark, or page action, see the section in the Acrobat online help, “Adding Navigation to Adobe PDF Documents” > “Using Actions for special effects” > “About action types”.
Using Acrobat JavaScript in Forms Working with document level JavaScript actions 2. Type the name of the script in the text box. 3. Click Add. 4. Copy and paste a predefined custom script, or type the script in the text box provided, and then click OK.
Using Acrobat JavaScript in Forms Creating form fields programmatically Document Did Save runs the JavaScript after the document is saved. Document Will Print runs the JavaScript while the document is printed. Document Did Print runs the JavaScript after the document is printed. 3.
Page 63
Using Acrobat JavaScript in Forms Creating form fields programmatically There are seven types of form fields, described in detail in the following sections: Button List Box Signature Check Box Radio Button Text Combo Box A form field may be created either through the Form toolbar in the Acrobat UI, or by the method of the Object.
Using Acrobat JavaScript in Forms Creating form fields programmatically All field types have the same properties availabe in the General tab of the Properties dialog. It is possible through the UI in Acrobat to specify the Appearance of the field, its Options and its Actions, all of which appear as tabs in the UI for a button field.
Page 65
Using Acrobat JavaScript in Forms Creating form fields programmatically Appearance Tab The Appearance tab allows you to set the basic appearance of the field. The table below summarizes how the appearance can be set programmatically using JavaScript. Region/Name See Reference Example Borders and Colors Border Color...
Appearance Tab for buttons. There is one difference, however — there is no choice for textFont. In the case of a check box, the font is always Adobe Pi. Options Tab The Options tab allows you to set the style of check mark used in the field and the export value.
Using Acrobat JavaScript in Forms Creating form fields programmatically Table Notes. Check box is checked by default: After using defaultIsChecked, the field is not necessarily checked. To check the field, either reset the field, this.resetForm([f.name]), or apply the : f.checkThisBox(0); checkThisBox Check box is checked by default: To determine if the “Check box is checked by default”...
Page 68
Using Acrobat JavaScript in Forms Creating form fields programmatically Table Notes. Item and Export Value: After a combo box is created with addField. the item names their export values can easily be introduced using setItems; for example f.setItems([ ["California", "CA"], ["Ohio", "OH"], ["Arizona", "AZ"] ]);...
Page 69
Using Acrobat JavaScript in Forms Creating form fields programmatically Region/Name See Reference Example Time AFTime_Format() Special AFSpecial_Format() Custom see table notes Table Notes. Number: The example in the table corresponds to a comma delimited euro currency with two decimal points in the UI. Custom: Any format script that does not use the above mentioned format functions is classified as custom formatting script.
Using Acrobat JavaScript in Forms Creating form fields programmatically Calculate Tab The action of the combo box can be set with the field level and a trigger name setAction of "Calculate". The UI has three categories of Calculate, the JavaScript counterpart is the method, as listed in the table below.
Using Acrobat JavaScript in Forms Creating form fields programmatically Options Tab Options Tab show the same set of properties as the comobox, with the exception that Allow user to enter custom text and Check spelling are not available and Multiple selection is available.
Using Acrobat JavaScript in Forms Creating form fields programmatically Appearance Tab The Appearance tab shows the same set of properties as for buttons. For details, see the Appearance Tab for buttons. Options Tab Options Tab of a radio button field is the same as that of a check box. The Table Notes are applicable as well.
= this.addField("mySignature", "signature", 0, [200, 500, 500, 400]); f.strokeColor = color.black; // set it to lock when signed f.setAction("Format", 'AFSignature_Format("THESE", new Array ("mySignature"));' ); var ppklite = security.getHandler("Adobe.PPKLite"); // choose handler ppklite.login("dps017", "/C/signatures/DPSmith.pfx"); // login f.signatureSign(ppklite, // sign it { password: "dps017",...
Page 74
Using Acrobat JavaScript in Forms Creating form fields programmatically Region/Name See Reference Example Default Value defaultValue f.defaultValue = "Name: "; Multiline multiline f.multiline = true; Scroll long text doNotScroll f.doNotScroll = true; Allow Rich Text Formatting richText f.richText = true; Limit of # characters charLimit f.charLimit = 40;...
Document level By using the Adobe Acrobat menu item Advanced > JavaScript > Document JavaScripts…, you 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.
A Short Acrobat JavaScript FAQ How should I name my form fields? within the PDF document. Therefore, the forms programmer should make every effort to package scripts as effectively as possible. FDF programmers should also be aware that FDF files can include document-level scripts and can also include scripts specified to be executed just before the FDF gets imported or executed right after the FDF gets imported.
A Short Acrobat JavaScript FAQ How do I use date objects? 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: var name = this.getfield("Name");...
Page 78
A Short Acrobat JavaScript FAQ How do I use date objects? To convert a Date object into a string, the printd of the Util Object is used. Unlike the built- in conversion of the Date object to a string, allows an exact specification of how printd the date should be formatted.
A Short Acrobat JavaScript FAQ How do I use date objects? Converting from a string to a date To convert a string into a Date object the of the Util Object is used. It accepts a scand format string that it uses as a hint as to the order of the year, month, and day in the input string.
Page 80
A Short Acrobat JavaScript FAQ How do I use date objects? 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.
A Short Acrobat JavaScript FAQ How can I make my document secure? How can I make my document secure? Security in Acrobat takes on the form of restricting access to a document, restricting permissions for a form once it has been opened, and digital signatures. Restricting Access to the Document 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...
ID. For details on where you can obtain digital IDs and the procedures for using them to sign documents, see “Creating a certifying signature” in Adobe Acrobat 6.0 Help. The recipient should trust the signer for certified documents and JavaScript.
Beginning with the 4.05 release of Acrobat, Adobe has worked to allow motion and vision impaired users to fill out Acrobat Forms. Version 6 of Acrobat is more fully speech-enabled than ever.
A Short Acrobat JavaScript FAQ How can I define globals in JavaScript? Short Description Every field that is not hidden must contain a user name (tooltip) that is user friendly. This name is spoken when a user acquires the focus to that field and should give an indication of the field’s purpose.
A Short Acrobat JavaScript FAQ How can I send form data to an e-mail address? Making Globals Persistent Global data does not persist across user sessions unless you specifically make your globals persistent. The predefined Global object has a method designed to do this. To make a variable named 'myVariable' persist across sessions, do this: global.setPersistent("myVariable",true);...
A Short Acrobat JavaScript FAQ How can I intercept keystrokes one by one as they occur? Then, when your document (Document A) wants to access the value of interest from the other form (Document B), it can subscribe to the variable in question: global.subscribe("xyz_value", ValueUpdate);...
A Short Acrobat JavaScript FAQ How can I prompt the user for a response in a dialog? How can I prompt the user for a response in a dialog? Use the defined in the App Object class. This method displays a dialog box response containing a question and an entry field for the user to reply to the question.
A Short Acrobat JavaScript FAQ How can I determine if the mouse has entered/left a certain area? How can I determine if the mouse has entered/left a certain area? Create an invisible, read-only text field at the place where you want to detect mouse entry or exit.
Need help?
Do you have a question about the 12001196 - Acrobat - Mac and is the answer not in the manual?
Questions and answers