“Where is” series, entering document Actions

Learn how to create document Actions, JavaScript events triggered by printing, saving, and closing the PDF.

By July 7, 2006

 

Scope: Acrobat Professional 6.0 and greater
Skill Level: Beginner
Prerequisites: Familiarity with Acrobat Professional

Document Actions are JavaScript events triggered by printing, saving, and closing the PDF. These Actions give developers the opportunity to change the PDF before and after one of these activities (except for closing). Some uses for these actions are making a stamp visible before printing, changing a date field before saving, or shutting down a timer when the document is closed.

Accessing Document Scripts

To edit or create a Document Action script, use the menu item:

Advanced>JavaScript>Set Document Actions …

This menu item displays the Document Actions Dialog (Figure 1). There are 5 Document Actions displayed in the list on this dialog.

Action

Description

Will Close

Triggered immediately before the PDF is closed. Used mainly for clean up; Ex: killing timers and multimedia displays.

Will Save

Triggered immediately before the PDF is saved. Used mainly to make automatic changes to the PDF so the saved document is unique.

Did Save

Triggered immediately after the PDF is saved. Used mainly to restore changes made to the PDF in the Will Save Action.

Will Print

Triggered immediately before the PDF is printed. Used mainly to make visual changes to the PDF, such as making a stamp or header visible.

Did Print

Triggered immediately after the PDF is put on the print queue. Used mainly to restore changes made to the PDF in the Will Print Action.

If one of the Actions contains a script, a green dot will appear to the left of the list entry. In Figure 1 the Will Close Action is marked as having a script, and the first few lines are displayed at the bottom of the dialog.


Figure 1 – Editing Document Actions

  • To edit or create a Document Action: Select it from the list of actions and press the Edit… button.
  • To remove a Document Action: Select it from the list of actions and press the Edit… button. Delete the entire script in the editor window.
  • Pressing the Edit All… button is the same as selecting the Advanced>JavaScript>Edit All JavaScripts button.

Some Notes on the Document Close Event

There is no Did Close Action. After the document is closed, everything on the document is unavailable to the JavaScript Engine. What context would such a script operate in? It would not be able to use or change anything about the document since it’s already closed.

It may also occur to some readers that the Will Close Action could be used to hide changes in the PDF (by setting doc.dirty property to false) so that Acrobat never asks the user if they want to save the document. You can’t do this! The Will Close Action happens after this dialog is displayed.


Did you know?

  • You can ask a question and get an answer from one of our experts.
  • You can search our database of over 800 tutorials by product and/or topic.
  • You can leave a comment below for the author of this tutorial.

Products covered:

Acrobat XIAcrobat XAcrobat 9

Related topics:

JavaScript

Top Searches:

Edit PDF, create PDF, Action Wizard

0 comments

Comments for this tutorial are now closed.

Comments for this tutorial are now closed.