From 412f01aeaf69821daa957203c86dae3f45db46f1 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 6 Mar 2021 18:21:34 +0100 Subject: [PATCH] Dispatch a "Doc/WillClose" event, when scripting is enabled, when closing the document This event is mentioned in the specification, see https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/AcrobatDC_js_api_reference.pdf#G5.1963176, and it's also listed as a valid type in https://github.com/mozilla/pdf.js/blob/fb87704b386bdc940ceef4eff31b1374432a6122/src/shared/util.js#L164-L170 Since we're already dispatching a "PageClose" event in this case, it seems reasonable to *also* dispatch a "Doc/WillClose" event as well. --- web/pdf_scripting_manager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index 32c9d0e2b..e8e98d174 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -128,6 +128,11 @@ class PDFScriptingManager { this._internalEvents.set("pagesdestroy", async event => { await this._dispatchPageClose(this._pdfViewer.currentPageNumber); + await this._scripting?.dispatchEventInSandbox({ + id: "doc", + name: "WillClose", + }); + this._closeCapability?.resolve(); });