Skip to content

动作变更历史 ​

本页按版本记录 PDF Action 相关接口的变化。

统一 Action 入口(v12.0.0+) ​

自 v12.0.0 起,ActionCallbackManager 已废弃。处理各类 PDF Action 时,PDFViewCtrl.PDFViewer 写在构造参数 customs.actionExecutor 上;UIExtension.PDFUI 写在 viewerOptions.customs.actionExecutor 上,不要写在 PDFUI 自己的 customs 上。JavaScript Action 不会进入该回调,始终由 SDK 内部执行。下面的示例按 PDFViewer 书写。

javascript
const pdfViewer = new PDFViewCtrl.PDFViewer({
    customs: {
        actionExecutor: async (options) => {
            const { ActionType } = PDFViewCtrl.PDF.actions;
            const { type, data } = options.actionData || {};
            switch (type) {
                case ActionType.gotoE: {
                    const { fileName, buffer } = data?.rootFile || {};
                    if (buffer) {
                        await options.pdfViewer.openPDFByFile(buffer, { fileName });
                    }
                    return true; // 已处理,跳过 SDK 默认行为
                }
                case ActionType.uri: {
                    const uri = data?.uri;
                    if (typeof uri !== 'string' || !uri.trim()) {
                        return true; // 缺少 URI,跳过 SDK 默认行为
                    }
                    try {
                        const parsedUrl = new URL(uri, window.location.href);
                        if (!['http:', 'https:', 'mailto:'].includes(parsedUrl.protocol)) {
                            return true; // 已拦截,跳过 SDK 默认行为
                        }
                    } catch {
                        return true; // 无效 URI,跳过 SDK 默认行为
                    }
                    return false; // 交由 SDK 继续默认处理
                }
                default:
                    return false;
            }
        }
    }
});
  • 回调签名为 (options) => Promise<boolean>。返回 true 表示已由自定义逻辑处理,SDK 跳过内置执行;返回 false 表示继续默认处理。
  • 可通过 options.actionData 读取类型与数据,并通过 options.doc、options.ownerQuery、options.pdfViewer、options.trigger 读取上下文。

v11.0 动作数据接口 ​

v11.0 起,读取和修改动作使用各对象上的数据接口,不再使用已废弃的 Action 类:

  • getActionData() / getAllActionData()
  • updateAction(targetActionObjNumber, actionData)
  • removeAction(targetActionObjNumber)
  • getAdditionalAction()

迁移代码见 PDF 动作接口迁移指南(v11.0)。用法见 动作(Action)。