1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-23 00:28:06 +02:00

Merge pull request #16766 from calixteman/fix_willprint

Make sure WillPrint ran before starting printing
This commit is contained in:
calixteman 2023-07-30 18:37:26 +02:00 committed by GitHub
commit 621c92dbdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 20 deletions

View file

@ -21,8 +21,14 @@ const FORMS_VERSION = 21.00720099;
const USERACTIVATION_CALLBACKID = 0;
const USERACTIVATION_MAXTIME_VALIDITY = 5000;
function serializeError(error) {
const value = `${error.toString()}\n${error.stack}`;
return { command: "error", value };
}
export {
FORMS_VERSION,
serializeError,
USERACTIVATION_CALLBACKID,
USERACTIVATION_MAXTIME_VALIDITY,
VIEWER_TYPE,

View file

@ -16,6 +16,7 @@
import { createActionsMap } from "./common.js";
import { PDFObject } from "./pdf_object.js";
import { PrintParams } from "./print_params.js";
import { serializeError } from "./app_utils.js";
import { ZoomType } from "./constants.js";
const DOC_EXTERNAL = false;
@ -126,20 +127,29 @@ class Doc extends PDFObject {
}
_dispatchDocEvent(name) {
if (name === "Open") {
this._disableSaving = true;
this._runActions("OpenAction");
this._disableSaving = false;
} else if (name === "WillPrint") {
this._disablePrinting = true;
this._runActions(name);
this._disablePrinting = false;
} else if (name === "WillSave") {
this._disableSaving = true;
this._runActions(name);
this._disableSaving = false;
} else {
this._runActions(name);
switch (name) {
case "Open":
this._disableSaving = true;
this._runActions("OpenAction");
this._disableSaving = false;
break;
case "WillPrint":
this._disablePrinting = true;
try {
this._runActions(name);
} catch (error) {
this._send(serializeError(error));
}
this._send({ command: "WillPrintFinished" });
this._disablePrinting = false;
break;
case "WillSave":
this._disableSaving = true;
this._runActions(name);
this._disableSaving = false;
break;
default:
this._runActions(name);
}
}

View file

@ -34,6 +34,7 @@ import { Color } from "./color.js";
import { Console } from "./console.js";
import { Doc } from "./doc.js";
import { ProxyHandler } from "./proxy.js";
import { serializeError } from "./app_utils.js";
import { Util } from "./util.js";
function initSandbox(params) {
@ -214,8 +215,7 @@ function initSandbox(params) {
try {
functions[name](args);
} catch (error) {
const value = `${error.toString()}\n${error.stack}`;
send({ command: "error", value });
send(serializeError(error));
}
};
}