Make sure WillPrint ran before starting printing
This commit is contained in:
parent
7ae5a0fef7
commit
8439e11160
@ -21,8 +21,14 @@ const FORMS_VERSION = 21.00720099;
|
|||||||
const USERACTIVATION_CALLBACKID = 0;
|
const USERACTIVATION_CALLBACKID = 0;
|
||||||
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
|
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
|
||||||
|
|
||||||
|
function serializeError(error) {
|
||||||
|
const value = `${error.toString()}\n${error.stack}`;
|
||||||
|
return { command: "error", value };
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
FORMS_VERSION,
|
FORMS_VERSION,
|
||||||
|
serializeError,
|
||||||
USERACTIVATION_CALLBACKID,
|
USERACTIVATION_CALLBACKID,
|
||||||
USERACTIVATION_MAXTIME_VALIDITY,
|
USERACTIVATION_MAXTIME_VALIDITY,
|
||||||
VIEWER_TYPE,
|
VIEWER_TYPE,
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
import { createActionsMap } from "./common.js";
|
import { createActionsMap } from "./common.js";
|
||||||
import { PDFObject } from "./pdf_object.js";
|
import { PDFObject } from "./pdf_object.js";
|
||||||
import { PrintParams } from "./print_params.js";
|
import { PrintParams } from "./print_params.js";
|
||||||
|
import { serializeError } from "./app_utils.js";
|
||||||
import { ZoomType } from "./constants.js";
|
import { ZoomType } from "./constants.js";
|
||||||
|
|
||||||
const DOC_EXTERNAL = false;
|
const DOC_EXTERNAL = false;
|
||||||
@ -126,19 +127,28 @@ class Doc extends PDFObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_dispatchDocEvent(name) {
|
_dispatchDocEvent(name) {
|
||||||
if (name === "Open") {
|
switch (name) {
|
||||||
|
case "Open":
|
||||||
this._disableSaving = true;
|
this._disableSaving = true;
|
||||||
this._runActions("OpenAction");
|
this._runActions("OpenAction");
|
||||||
this._disableSaving = false;
|
this._disableSaving = false;
|
||||||
} else if (name === "WillPrint") {
|
break;
|
||||||
|
case "WillPrint":
|
||||||
this._disablePrinting = true;
|
this._disablePrinting = true;
|
||||||
|
try {
|
||||||
this._runActions(name);
|
this._runActions(name);
|
||||||
|
} catch (error) {
|
||||||
|
this._send(serializeError(error));
|
||||||
|
}
|
||||||
|
this._send({ command: "WillPrintFinished" });
|
||||||
this._disablePrinting = false;
|
this._disablePrinting = false;
|
||||||
} else if (name === "WillSave") {
|
break;
|
||||||
|
case "WillSave":
|
||||||
this._disableSaving = true;
|
this._disableSaving = true;
|
||||||
this._runActions(name);
|
this._runActions(name);
|
||||||
this._disableSaving = false;
|
this._disableSaving = false;
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
this._runActions(name);
|
this._runActions(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import { Color } from "./color.js";
|
|||||||
import { Console } from "./console.js";
|
import { Console } from "./console.js";
|
||||||
import { Doc } from "./doc.js";
|
import { Doc } from "./doc.js";
|
||||||
import { ProxyHandler } from "./proxy.js";
|
import { ProxyHandler } from "./proxy.js";
|
||||||
|
import { serializeError } from "./app_utils.js";
|
||||||
import { Util } from "./util.js";
|
import { Util } from "./util.js";
|
||||||
|
|
||||||
function initSandbox(params) {
|
function initSandbox(params) {
|
||||||
@ -214,8 +215,7 @@ function initSandbox(params) {
|
|||||||
try {
|
try {
|
||||||
functions[name](args);
|
functions[name](args);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const value = `${error.toString()}\n${error.stack}`;
|
send(serializeError(error));
|
||||||
send({ command: "error", value });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ class PDFScriptingManager {
|
|||||||
|
|
||||||
#scripting = null;
|
#scripting = null;
|
||||||
|
|
||||||
|
#willPrintCapability = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {PDFScriptingManagerOptions} options
|
* @param {PDFScriptingManagerOptions} options
|
||||||
*/
|
*/
|
||||||
@ -203,10 +205,23 @@ class PDFScriptingManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async dispatchWillPrint() {
|
async dispatchWillPrint() {
|
||||||
return this.#scripting?.dispatchEventInSandbox({
|
if (!this.#scripting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.#willPrintCapability?.promise;
|
||||||
|
this.#willPrintCapability = new PromiseCapability();
|
||||||
|
try {
|
||||||
|
await this.#scripting.dispatchEventInSandbox({
|
||||||
id: "doc",
|
id: "doc",
|
||||||
name: "WillPrint",
|
name: "WillPrint",
|
||||||
});
|
});
|
||||||
|
} catch (ex) {
|
||||||
|
this.#willPrintCapability.resolve();
|
||||||
|
this.#willPrintCapability = null;
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.#willPrintCapability.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async dispatchDidPrint() {
|
async dispatchDidPrint() {
|
||||||
@ -306,6 +321,10 @@ class PDFScriptingManager {
|
|||||||
pdfViewer.decreaseScale();
|
pdfViewer.decreaseScale();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "WillPrintFinished":
|
||||||
|
this.#willPrintCapability?.resolve();
|
||||||
|
this.#willPrintCapability = null;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -432,6 +451,9 @@ class PDFScriptingManager {
|
|||||||
await this.#scripting.destroySandbox();
|
await this.#scripting.destroySandbox();
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
|
this.#willPrintCapability?.reject(new Error("Scripting destroyed."));
|
||||||
|
this.#willPrintCapability = null;
|
||||||
|
|
||||||
for (const [name, listener] of this._internalEvents) {
|
for (const [name, listener] of this._internalEvents) {
|
||||||
this.#eventBus._off(name, listener);
|
this.#eventBus._off(name, listener);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user