# PDF Action API Migration Guide
This chapter focuses on the migration of PDF Action related APIs from the previous version to the new version, aiming to assist developers in upgrading their code smoothly.
# Changes in Action Retrieval and Manipulation APIs
# Previous Version
// Get Additional Action object
Widget#getAdditionalAction(type)
// Get Action object
Widget#getAction();
// Remove Additional Action object from a Link
Link#removeAction(trigger, action);
// Remove Additional Action object from a Screen
Screen#removeAction(trigger, action);
# New Version
// Note: Here, Annot refers to Widget, Screen, Link, and Sound
// Get Action information
await Annot#getActionData();
// Get all Action information (including Additional Action and regular Action)
await Annot#getAllActionData();
// Update a specific Action
await Annot#updateAction(targetActionObjNumber, actionData);
// Remove a specific Action
await Annot#removeAction(targetActionObjNumber);
// Get the AdditionalAction object
const additionalAction = await Annot#getAdditionalAction();
// Remove an Additional Action based on trigger type and Action object number
await additionalAction.removeAction(trigger, targetActionObjNumber);
// Add a new Action
await additionalAction.addAction(trigger, actionSpec);
// Update the information of a specific Action
await additionalAction.updateActionData(trigger, targetActionObjNumber, actionData);
// Override all Action for a specific trigger type
await additionalAction.setAction(trigger, actionSpec);
# Key Changes Description
In the previous version, Action was accessed using
Widget#getActionandWidget#getAdditionalAction(type)methods.In the new version, Action is managed uniformly through asynchronous methods of the
Annotobject, which includes Widget, Screen, Link, and Sound.The new version adds more granular capabilities for handling Action, such as batch retrieval, updates, and deletions.
For operations related to AdditionalAction, the new version requires first obtaining the AdditionalAction object via the
Annot#getAdditionalAction()method, followed by performing actions such as adding, removing, updating, and querying.
# Changes in Action Callback APIs
# Previous Version (before v9.1.0)
In the previous version, callbacks were registered via ActionCallbackManager#setEmbeddedGotoCallback, and the callback parameter was an EmbeddedGotoAction (opens new window) object:
const actionCallbackManager = pdfViewer.getActionCallbackManager();
actionCallbackManager.setEmbeddedGotoCallback(async (action) => {
console.log(action.getDestination());
});
# Transitional Version (v9.1.0 – v10.x)
Starting from v9.1.0, the callback parameter was changed to an ExecuteActionOptions (opens new window) object, which includes action data, document objects, and trigger source information:
const actionCallbackManager = pdfViewer.getActionCallbackManager();
actionCallbackManager.setEmbeddedGotoCallback(async (options) => {
const { type, data } = options.actionData;
console.log(
options.actionData,
options.doc,
options.ownerQuery,
options.pdfViewer,
options.trigger
);
// Custom Embedded GoTo: e.g. open the target PDF from an embedded file
if (data.rootFile) {
const { fileName, buffer } = data.rootFile;
if (buffer) {
await options.pdfViewer.openPDFByFile(buffer, { fileName });
}
}
});
# New Version (v12.0.0+)
Starting from v12.0.0, ActionCallbackManager is deprecated. Use the PDFViewer constructor option options.customs.actionExecutor to intercept all types of PDF Actions in a unified way (JavaScript Actions are excluded and are always executed internally by the SDK):
const pdfViewer = new PDFViewCtrl.PDFViewer({
customs: {
actionExecutor: async (options) => {
const { ActionType } = PDFViewCtrl.PDF.actions;
const { type, data } = options.actionData;
switch (type) {
case ActionType.gotoE: {
// Custom Embedded GoTo: e.g. open the target PDF from an embedded file
const { fileName, buffer } = data.rootFile || {};
if (buffer) {
await options.pdfViewer.openPDFByFile(buffer, { fileName });
}
return true; // Fully handled by custom logic; skip the SDK built-in executor
}
case ActionType.uri: {
console.log('URI action:', data.uri);
return false; // Allow the SDK to proceed with default handling
}
default:
return false;
}
}
}
});
# Major Changes Description
- In the transitional version, the callback parameter was changed from an Action object to
ExecuteActionOptions(opens new window). Useoptions.actionDatato access action type and data, andoptions.doc,options.ownerQuery,options.pdfViewer, andoptions.triggerfor context information. - Starting from v12.0.0,
options.customs.actionExecutoris recommended to replace the scattered callbacks ofActionCallbackManager. A single callback can handle multiple Action types based onoptions.actionData.type. - The
actionExecutorcallback signature is(options: ExecuteActionOptions) => Promise<boolean>. Returntrueif the action has been fully handled by custom logic and the SDK should skip its built-in executor; returnfalseto allow the SDK to proceed with default action handling. - JavaScript Actions do not enter the
actionExecutorcallback and are always executed internally by the SDK. - For specific fields, please refer to the API Documentation (opens new window).
For more detailed information, please refer to the API Reference Documentation (opens new window).