PDF Annotation Actions on iOS
A PDF action is similar to a web hyperlink, but it’s much more flexible. PSPDFKit supports most common actions defined in Adobe’s PDF Reference (page 417ff).
Action subclass can either be parsed from a PDF or created in code. It can also be serialized via
|Action||PSPDFKit Class||Use Case|
||Go to a destination (page) in the current document.|
||Go to a destination in another document.|
||Go to a destination in an embedded file.|
||Launch an application, usually to open a file.|
||Resolve a uniform resource identifier (web link).|
||Set an annotation’s hidden flag.|
||Control the playing of multimedia content.|
||Send data to a uniform resource locator.|
||Set fields to their default values.|
||Execute an action predefined by the conforming reader.|
Unsupported actions include Thread, Sound, Movie, ImportData, SetOCGState, Trans, and GoTo3DView.
Actions are chainable via the
subActions property. Certain annotations, such as
WidgetAnnotation, can contain an
action. Furthermore, every annotation can contain
additionalActions that are executed on certain trigger events. You can use the
additionalActions property to add actions to annotation types that don’t have an action handler by default, such as stamp annotations. In most cases, the
Annotation.TriggerEvent.mouseUp event is what you want.
OutlineElement also contain an
action, thereby supporting the same types of actions as an annotation. (A PDF outline can open a web link or even play a video.)
Annotation.TriggerEvent for available trigger events. PSPDFKit supports a subset of these events.
You can use
execute(_:targetRect:pageIndex:animated:actionContainer:) to execute PDF actions, such as the
action property of
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];
ℹ️ Note: The file structure for the action has to be correctly specified for it to work, and the files in question should be in a local folder.