JavaScript Debugging

If you use the JavaScript language for a script, you can use the console.println("string") function to output information to the JavaScript Console available in Acrobat Professional. Alternatively, yu can use the alert method from the Acrobat JavaScript Object Model to debug JavaScript.

JavaScript Debugger in Acrobat Professional

The JavaScript Debugger in Acrobat Professional lets you test JavaScripts scripts. The debugger includes the JavaScript Console, where you can test portions of JavaScript code in the Preview PDF tab. The JavaScript Console provides an interactive and convenient interface for testing portions of JavaScript code and experimenting with object properties and methods. Because of its interactive nature, the JavaScript Console behaves as an editor that supports the execution of single lines or blocks of code.

To enable the JavaScript Debugger for Designer and execute code from the JavaScript Console, enable JavaScript and the JavaScript Debugger in Acrobat Professional.

Note: You can enable the JavaScript Debugger in Adobe Reader if you have Adobe® LiveCycle® Reader® Extensions 10 installed. To enable the JavaScript Debugger in Adobe Reader, you must get the debugger.js file and then edit the Microsoft Windows Registry. For more information about enabling the JavaScript Debugger in Adobe Reader, see Developing Acrobat Applications Using JavaScript (English only).

To enable the JavaScript Debugger for Designer

  1. Start Designer.

  2. Start Acrobat Professional.

  3. In Acrobat Professional, select Edit > Preferences.

  4. Select JavaScript from the list on the left.

  5. Select Enable Acrobat JavaScript if it is not already selected.

  6. Under JavaScript Debugger, select Enable JavaScript Debugger After Acrobat Is Restarted.

  7. Select Enable Interactive Console. This option lets you evaluate code that you write in the JavaScript Console.

  8. Select Show Console On Errors And Messages. This option ensures that if you make mistakes, the JavaScript Console displays helpful information.

  9. Click OK to close the Preferences dialog box.

  10. Quit Acrobat Professional.

  11. In Designer, click the Preview PDF tab.

  12. Press Ctrl+J to open the JavaScript Debugger.

To prevent the JavaScript Debugger from disappearing in Designer

If the JavaScript Debugger from Acrobat is active and it disappears when you click components in the Designer interface, stop the Acrobat.exe process in the Microsoft Windows Task Manager. The Acrobat.exe process continues to run after Acrobat is closed so that Acrobat is displayed faster if it is restarted. Stopping the process ends the association between the JavaScript Debugger and the Acrobat Professional session so that you can use the JavaScript Debugger in Designer.

  1. In the Windows Task Manager, click the Processes tab.

  2. In the Image Name column, right-click Acrobat.exe and select End Process.

Evaluating code using the JavaScript Console

There are three ways evaluate single and multiple lines of code using the JavaScript Console from Acrobat.

To evaluate a portion of a line of code

 Highlight the portion in the console window and press either Enter on the numeric keypad or Ctrl+Enter on the regular keyboard.

To evaluate a single line of code

 Place the cursor is in the appropriate line in the console window and press Enter on the numeric keypad or Ctrl+Enter on the regular keyboard.

To evaluate multiple lines of code

 Highlight those lines in the console window and press either Enter on the numeric keypad or Ctrl+Enter on the regular keyboard.

To delete content that appear in the JavaScript Console

 Click Clear in the console window.

The result of the most recently evaluated JavaScript script is displayed in the console window.

After evaluating each JavaScript script, the console window prints out undefined, which is the return value of the statement. Notice that the result of a statement is not the same as the value of an expression within the statement. The return value undefined does not mean that the value of script is undefined; it means that the return value of the JavaScript statement is undefined.

Providing debugging feedback to the JavaScript Console

If you are creating scripts using JavaScript, you can output messages to the JavaScript Console from Acrobat at runtime by using the console.println method included with the JavaScript Object Model from Acrobat. When initiated, the console.println method displays a string value in the JavaScript Console. The string value can be a text message that you create for debugging purposes or the string value of fields or expressions.

For example, consider a simple form design that contains a single numeric field (NumericField1) and a button (Button1). In this case, the following JavaScript script outputs a message displaying some text and the value currently displayed in the numeric field. By adding either the calculation or the script to the click event of the button object, you can interactively display the value of the numeric field in a new dialog box by clicking the button.

    console.println("The value is: " + NumericField1.rawValue);

For more information about the console.println method and the JavaScript Object Model from Acrobat, see Developing Acrobat Applications Using JavaScript (English only).

For more information about the JavaScript Console and the JavaScript Debugger, see Developing Acrobat Applications Using JavaScript(English only).

Providing debugging feedback using the alert method

If you want to return a message box during a calculate event, you can take advantage of the alert method from the JavaScript Object Model from Acrobat. For example, the following script returns the value of a text field:

    var oField = xfa.resolveNode("TextField1").rawValue; app.alert(oField);

For more information about the alert method and the JavaScript Object Model from Acrobat, see Developing Acrobat Applications Using JavaScript (English only).

// Ethnio survey code removed