Looking for:
- Adobe acrobat x pro javascript guide freeFile conformi a PDF/X, PDF/A- e PDF/E- (Adobe Acrobat Pro).Tutorials : JavaScript
The Console Window section of the Debugger is in the bottom portion of the dialog, in the area labeled View. In Figure 3, the View pull-down selection list is set to Console, meaning the Console Window is being shown. This area is also used to show the Script window for displaying runtime code when the debugger tools are enabled.
In the figure, the Console is being shown immediately after Acrobat was started. The status messages are displayed by code built-into Acrobat and loaded on startup.
Each line represents a JavaScript module loaded by Acrobat. If there were any problems with these modules, or any others that Acrobat loads, error messages would also be displayed here. Normally, we're not interested in these initial messages. So if you would like to try out some of the code presented here as examples, then clear the window by pressing the button that looks like a garbage can in the lower right corner of the window.
Now we have a clean work area and are set up and ready to start using the Console Window. JavaScript code can be executed directly from the Console Window. This ability is a huge time saver since it provides a fast and easy way to test out code before it's placed into a scripting location where it will be more difficult to debug.
To run the code, make sure the cursor is on the same line as the text. You can place it anywhere on the line as long as nothing is selected. Either of the two following actions will cause Acrobat to run the code. Acrobat always attempts to convert the result of an execution into text so that it can be displayed. Sometimes the result of an operation is not as clean or obvious as a number. Let's try something that doesn't have such a well-defined result. Enter the following line in the Console Window and run it:.
This calculation has an obvious mathematical error, but Acrobat JavaScript doesn't display an error message. Instead, as shown in Figure 5 , it displays the word "Infinity. 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. The next line of example code is something that might be used in a real script.
It assigns a simple addition to a variable named 'sum'. As shown in Figure 6, the return value from this line of code is "undefined. The calculation is executed and applied to the declared variable, sum. 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. Unfortunately, variable declarations do not return a value.
To overcome this small issue, the Console widow displays "undefined. Anything that doesn't exist to the JavaScript environment is "undefined. This action executes just the selected text. This technique of selecting parts of the code for execution is also useful for executing multiple lines of code. 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.
Immediate Mode means that anything entered into this window is executed directly by the JavaScript engine. We can use it anytime we want to execute code for any purpose.
Two uses for the Console Window besides code testing that immediately come to mind are automation and analysis. There are several functions in Acrobat for manipulating and for acquiring information from PDFs and Acrobat. 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.
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. Assuming the current document has a field with the correct name on it, the following code displays the raw color value in the Console Window:. The result of this operation is a color array.
Remember, Acrobat attempts to convert all results into text. Arrays 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. This is an example of document analysis with JavaScript. 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.
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:. Suppose a document needs to be checked for branding purposes, i. The following code uses a simple loop to display this color info in the Console Window for manual inspection:.
Because of the loop, this code cannot be executed one line at a time. It has to be done all at once. Notice that in the loop there is a function called console. It's in the fourth line. This function writes text to the Console Window and it will be discussed in the next section. Here's an example of a function that does not have an easy equivalent on the regular Acrobat menus and toolbars. Enter the following line into the Console Window and run it:.
Acrobat will create a new, blank PDF document. This is perfect for trying out new ideas before applying them to a working document. The results of this operation are shown in Figure 7 below. Note that yet again, the result is something different. The result shown in Figure 7 tells us the type of object created. This result is only useful in letting us know the function worked. If app. Both of these situations would have been displayed in the Console Window. The path property is exactly what you might think it should be.
It's the folder path of the current document. Since the current document was just created with app. The result will look something like this:. Of course, this information is easily available in the Document Properties dialog. The advantage to using the Console Window is to make this information available to copy to the system clipboard for use with another script in Acrobat or for something else. Besides testing code, the Console Window has one other important role in debugging JavaScript.
It is the standard location for displaying status and error messages. The Acrobat JavaScript environment has a built-in error handling system. When something goes wrong, this error-handling system usually displays some helpful message sometimes in the Console Window, so this is the first place to look when things aren't working.
In addition, you can create your own status and error messages to display here. As an example, let's execute something that will cause an error. Enter and run the following line of code in the Console Window:. This line of code instructs Acrobat to open a file xx. Acrobat responds by generating an error, which is displayed by the Console Window, shown in Figure 8. This message is critical to understanding why the code failed, especially if the function call is buried in several lines of code inside another script.
Always check the Console Window first when something goes wrong. Note that the second message on the line indicates a security error. For our purposes, this is an erroneous and unhelpful message. There was no real security error, and while it may then seem that Adobe is deliberately trying to either terrify or confuse us, there is a reason the message is being displayed. In fact, the message is not related to the JavaScript engine at all. It is the result of the Acrobat security model, which was made much more robust in versions 9, X, and XI by adding a security layer.
This layer blocks operations that don't fit with Acrobat's sense of rightness. JavaScript operations or errors that relate to external resources on the web or local file system tend to spook this security layer, which then throws out miscellaneous security errors. If you work with Acrobat JavaScript for any length of time, you'll find all sorts of operations that have nothing to do with security, but nonetheless generate security errors.
We can also create our own messages for display in the Console Window. This object provides a few functions for manipulating and accessing the Console Window, but for our purposes here the console. This function displays a single line of text on the next available line in the Console Window. The Locked option prevents the appearance and actions associated with an object from being accidentally changed. From the Select Action menu, select the action type to occur, and then click Add.
You can add multiple actions; actions execute in the order that they appear in the Actions list box. Optional Select an action in the Actions tab, and use the buttons to reorder, edit, or delete the action.
Click OK to accept the actions. To close the Rich Media tool, click the cross icon at the right-end of the toolbar. To enhance the interactive quality of a document, you can specify actions, such as changing the zoom value, to occur when a page is opened or closed.
Select the page thumbnail corresponding to the page, and choose Page Properties from the options menu. From the Select Trigger menu, choose Page Open to set an action when the page opens, or choose Page Close to set an action when the page closes. Specify the options for the action, and click OK. The options available depend on the action selected. To create a series of actions, choose another action from the menu, and click Add again.
Use the Up and Down buttons to arrange the actions in the order you want them to occur. If you set an action that switches to Full Screen view on Page Open or Page Close, the next time the same page opens or closes, Full Screen view is turned on. Close all opened dialog boxes, if any. Click the cross icon at the right-end of the toolbar to close the tool. Execute A Menu Item. Go To A Page View. Import Form Data. Multimedia Operation Acrobat 9 And Later.
Executes a specified action for a multimedia object in the file such as playing a sound file. The multimedia object must be added to the file before you can specify an action for it. Launches and opens a file. If you are distributing a PDF file with a link to another file, the reader needs the native application of that linked file to open it successfully. You may need to add opening preferences for the target file.
Open A Web Link. Jumps to the specified destination on the Internet. You can use http, ftp, and mailto protocols to define your link. Play A Sound. Plays the specified sound file. The sound is embedded into the PDF document in a cross-platform format. Play Media Acrobat 5 Compatible. The specified movie must be embedded in a PDF document.
Plays a specified movie that was created as Acrobat 6-compatible. Read An Article. Reset A Form. Clears previously entered data in a form. You can control the fields that are reset with the Select Fields dialog box. Run A JavaScript. Set Layer Visibility. Determines which layer settings are active. Before you add this action, specify the appropriate layer settings. Toggles between showing and hiding a field in a PDF document.
This option is especially useful in form fields. For example, if you want an object to pop up whenever the pointer is over a button, you can set an action that shows a field on the Mouse Enter trigger and hides a field on Mouse Exit.
Submit A Form. Triggers determine how actions are activated in media clips, pages, and form fields. For example, you can specify a movie or sound clip to play when a page is opened or closed. The available options depend on the specified page element. Mouse Up Acrobat Pro. When the mouse button is released after a click. This is the most common button trigger, because it gives the user one last chance to drag the pointer off the button and not activate the action.
Page Visible media clips only. When the page containing the media clip is visible, regardless of whether it is the current page. Page Invisible media clips only.
Page Enter media clips only.
No comments:
Post a Comment