

The following code uses a simple loop to display this color info in the Console Window for manual inspection. Suppose a document needs to be checked for branding purposes, i. We can easily copy and paste this information to accomplish some other purpose, for example applying the color to another field with this line of code. We’ve just found out something that would have taken us just a little more effort to find out using the Acrobat property dialogs, and the information is in a very usable format. This is an example of document analysis with JavaScript. Remember, Acrobat attempts to convert all results into text.Īrrays are converted to text by converting each individual array element into a text string, so the result would look something like the following line when it is displayed in the Console Window. The result of this operation is a color array. For example, suppose you wanted to know the exact border color of a text field so you could use the same color in another location.Īssuming the current document has a field with the correct name on it, the following code displays the raw color value in the Console Window. For operations with a user interface button or menu item, the main advantage of using JavaScript is greater flexibility, since JavaScript functions typically provide more options than the user interface equivalent. There are several functions in Acrobat for manipulating and for acquiring information from PDFs and Acrobat. Two uses for the Console Window besides code testing that immediately come to mind are automation and analysis. We can use it anytime we want to execute code for any purpose. Immediate Mode means that anything entered into this window is executed directly by the JavaScript engine. So far we’ve talked about executing code in the Console Window for testing and debugging, but there is no reason to restrict our usage to this limited theme. This technique of selecting parts of the code for execution is also useful for executing multiple lines of code. This action executes just the selected text. Anything that doesn’t exist to the JavaScript environment is “undefined. To overcome this small issue, the Console widow displays “undefined. Unfortunately, variable declarations do not return a value. However, the first and primary operation on the line is the variable declaration, so this is the operation that returns a value to the Console Window.

The calculation is executed and applied to the declared variable, sum.

As shown in Figure 6, the return value from this line of code is “undefined. It assigns a simple addition to a variable named ‘sum’. The next line of example code is something that might be used in a real script. It is much easier to find this kind of issue by executing individual lines in the Console Window where you can see the results immediately, than it is to debug it from a field-calculation script. Instead, as shown in Figure 5, it displays the word “Infinity. This calculation has an obvious mathematical error, but Acrobat JavaScript doesn’t display an error message. Enter the following line in the Console Window and run it. Let’s try something that doesn’t have such a well-defined result. Sometimes the result of an operation is not as clean or obvious as a number. Acrobat always attempts to convert the result of an execution into text so that it can be displayed.

Either of the two following actions will cause Acrobat to run the code.
