Step 1: Check us out

You don't have to be a member to look at any content on the site. Increase your expertise with our helpful tutorials, videos, forums, and sample PDFs.

Step 2: Sign up for a free account

Like what you see? Take the next step and become a member. Register now to get discounts, attend eSeminars, ask questions and more.

Step 3: Start participating

Get the most out of your membership. Post in the forums, create your profile, submit to the gallery, attend a user group meeting. Log In now.

"Where is" Series, Entering Document Actions

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.



Acrobat Job Board

Looking for a job or seeking to fill a job? Check out the new Acrobat job board.

Job board >

Tech Talks

Go deeper into Acrobat through a new series of informal technical talks by Acrobat experts.

Tech Talks >

Membership

Sign up for your free membership today and save up to 40% on books, training, and more.

Join for free >