JS - Collect and execute actions at doc and pages level

* the goal is to execute actions like Open or OpenAction
 * can be tested with issue6106.pdf (auto-print)
 * once #12701 is merged, we can add page actions
This commit is contained in:
Calixte Denizet 2020-12-07 19:22:14 +01:00
parent 142f131ee1
commit 1e2173f038
18 changed files with 829 additions and 125 deletions

View file

@ -753,6 +753,17 @@ class PDFDocumentProxy {
return this._transport.getJavaScript();
}
/**
* @returns {Promise<Object | null>} A promise that is resolved with
* an {Object} with the JavaScript actions:
* - from the name tree (like getJavaScript);
* - from A or AA entries in the catalog dictionary.
* , or `null` if no JavaScript exists.
*/
getJSActions() {
return this._transport.getDocJSActions();
}
/**
* @typedef {Object} OutlineNode
* @property {string} title
@ -1124,6 +1135,20 @@ class PDFPageProxy {
return this.annotationsPromise;
}
/**
* @param {GetAnnotationsParameters} params - Annotation parameters.
* @returns {Promise<Array<any>>} A promise that is resolved with an
* {Array} of the annotation objects.
*/
getJSActions() {
if (!this._jsActionsPromise) {
this._jsActionsPromise = this._transport.getPageJSActions(
this._pageIndex
);
}
return this._jsActionsPromise;
}
/**
* Begins the process of rendering a page to the desired context.
*
@ -1405,6 +1430,7 @@ class PDFPageProxy {
}
this.objs.clear();
this.annotationsPromise = null;
this._jsActionsPromise = null;
this.pendingCleanup = false;
return Promise.all(waitOn);
}
@ -1438,6 +1464,7 @@ class PDFPageProxy {
this._intentStates.clear();
this.objs.clear();
this.annotationsPromise = null;
this._jsActionsPromise = null;
if (resetStats && this._stats) {
this._stats = new StatTimer();
}
@ -2631,6 +2658,16 @@ class WorkerTransport {
return this.messageHandler.sendWithPromise("GetJavaScript", null);
}
getDocJSActions() {
return this.messageHandler.sendWithPromise("GetDocJSActions", null);
}
getPageJSActions(pageIndex) {
return this.messageHandler.sendWithPromise("GetPageJSActions", {
pageIndex,
});
}
getOutline() {
return this.messageHandler.sendWithPromise("GetOutline", null);
}