Adobe PDF Library

Working with Actions in PDF files

An action is added to a PDF file to prompt a user response.  There are a variety of types of actions.  A reader can click on an action in a PDF file and move to a different section of the document, or run a hyperlink to open a web site, or launch a video.  It is also possible to add an action to a PDF file that runs automatically when the PDF file opens or when the reader reaches a given page.  The PDF Library provides a set of APIs to create and manage actions in a PDF file, and to attach them to items shown on the page.  For more detail on working with actions, see section 12.6 of the ISO 32000-1:2008, Document Management—Portable Document Format—Part 1: PDF 1.7, page 414.

All three of these sample programs demonstrate how to work with actions in a PDF file.

Action

View Sample Code

In this sample the program creates a PDF document with a single page, featuring a rectangle.  An action is added to the rectangle in the form of a hyperlink; if the reader clicks on the rectangle, the system opens a Datalogics web page.

LaunchActions

View Sample Code

In this sample the program creates a PDF document with a single blank page, featuring a rectangle.  An action is added to the rectangle in the form of a hyperlink; if the reader clicks on the rectangle, a different PDF file opens, showing an image.

RemoteGoToActions

View Sample Code

RemoteGoToActions is similar to LaunchActions.  The program generates a PDF file with an annotation, in the form of a rectangle.  Click on the rectangle shown in this PDF file and a separate PDF file opens.

RemoteGoToActions differs from LaunchActions in that it includes a RemoteDestination object.  This object describes the rectangle used in the PDF file in a series of statements at the command prompt.  It displays the following values:

  • page number where the rectangle appears
  • zoom level
  • fit type
  • x and y coordinates for placing the rectangle on the page, lower left (LL) and upper right (UR)

The FileSpecification and RemoteDestination objects in the program must be associated with the same PDF file.  The association happens when the object is created and cannot be changed within the file. We recommend that the FileSpecification take a relative path for the file, if you intend the program to work across all platforms, including Windows, Mac, and Unix.