PDF Actions

A PDF action is similar to a web hyperlink, but much more flexible. PSPDFKit supports nearly every action type defined in Adobe's PDF Reference. (Page 417ff)

The most common types are GoTo and URI, however many documents also use GoToR/Launch/Named/JavaScript for page changes.

Every PSPDFAction subclass can be either parsed from a PDF or created in code. It can also be serialized via NSKeyedArchiver (supporting NSSecureCoding) or serialized/deserialized via PSPDFJSONAdapter.

Action PSPDFKit Class Use Case
GoTo PSPDFGoToAction Go to a destination (page) in the current document.
GoToR PSPDFRemoteGoToAction Go to a destination in another document.
GoToE PSPDFEmbeddedGoToAction Go to a destination in an embedded file.
Launch PSPDFRemoteGoToAction Launch an application, usually to open a file.
URI PSPDFURLAction Resolve a uniform resource identifier (web link).
Hide PSPDFHideAction Set an annotation’s Hidden flag.
JavaScript PSPDFJavaScriptAction Execute a JavaScript script.
Rendition PSPDFRenditionAction Controls the playing of multimedia content.
SubmitForm PSPDFSubmitFormAction Send data to a uniform resource locator.
ResetForm PSPDFResetFormAction Set fields to their default values.
Named PSPDFNamedAction Execute an action predefined by the conforming reader.

Unsupported: Thread, Sound, Movie, ImportData, SetOCGState, Trans, GoTo3DView.

Actions are chain-able via the subActions property. Certain annotations such as the PSPDFLinkAnnotation or the PSPDFWidgetAnnotation can contain an action. Furthermore, every annotation can contain additional actions (additionalActions) that are executed on certain trigger events. You can use the additionalActions property to add actions to annotation types that by default don't have an action handler, such as stamp annotations. In most cases the PSPDFAnnotationTriggerEventMouseUp event is what you want.

A PSPDFBookmark and thus also a PSPDFOutlineElement also contain an action and thus support the same types of actions as an annotation. (A PDF Outline can open a web link or even play a video.)

Trigger Events

See PSPDFAnnotationTriggerEvent for available trigger events. PSPDFKit supports a subset of these events.

Executing Actions

You can use PSPDFViewController's -executePDFAction:targetRect:pageIndex:animated:actionContainer: to execute PDF actions, like the action property of PSPDFLinkAnnotation:

pdfController.execute(linkAnnotation.action, targetRect: linkAnnotation.boundingBox, pageIndex: linkAnnotation.absolutePageIndex, animated: true, actionContainer: linkAnnotation)
[pdfController executePDFAction:linkAnnotation.action targetRect:linkAnnotation.boundingBox pageIndex:linkAnnotation.absolutePageIndex animated:YES actionContainer:linkAnnotation];
Was this page helpful? We're happy to answer any questions.