PDF actions in React Native
A PDF action is similar to a web hyperlink, but it’s much more flexible. Nutrient supports most common actions defined in Adobe’s PDF Reference (page 417ff).
The most common types are GoTo and URI. However, many documents also use GoToR, Launch, Named, or JavaScript for page changes.
| Action | Use case |
|---|---|
| GoTo | Go to a destination (page) in the current document. |
| GoToR | Go to a destination in another document. |
| GoToE | Go to a destination in an embedded file. |
| Launch | Launch an application, usually to open a file. |
| URI | Resolve a uniform resource identifier (web link). |
| Hide | Set an annotation’s hidden flag. |
| JavaScript | Execute a JavaScript script. |
| Rendition | Control the playing of multimedia content. |
| SubmitForm | Send data to a uniform resource locator. |
| ResetForm | Set fields to their default values. |
| Named | Execute an action predefined by the conforming reader. |
Unsupported actions include Thread, Sound, Movie, ImportData, SetOCGState, Trans, and GoTo3DView.
Bookmark and 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.)
Intercepting actions
You can intercept actions by implementing the onShouldExecuteAction callback on NutrientView and returning false to prevent the action from executing:
<NutrientView ref={this.pdfRef} document={documentPath} onShouldExecuteAction={(event: ShouldExecuteActionEvent) => { // Inspect the `actionType` and URL and optionally allow the action to proceed. this.pdfRef.current?.executeAction(event.requestId, true); }}/> fragmentTag="PDF1" style={styles.pdfColor}/>