diff --git a/src/scripting_api/event.js b/src/scripting_api/event.js index e1713c9ec..30b5b1878 100644 --- a/src/scripting_api/event.js +++ b/src/scripting_api/event.js @@ -91,6 +91,9 @@ class EventDispatcher { if (id === "doc") { const eventName = event.name; if (eventName === "Open") { + // The user has decided to open this pdf, hence we enable + // userActivation. + this.userActivation(); // Initialize named actions before calling formatAll to avoid any // errors in the case where a formatter is using one of those named // actions (see #15818). diff --git a/test/integration/scripting_spec.js b/test/integration/scripting_spec.js index 72666a501..c60feb1cd 100644 --- a/test/integration/scripting_spec.js +++ b/test/integration/scripting_spec.js @@ -1753,4 +1753,31 @@ describe("Interaction", () => { ); }); }); + + describe("in autoprint.pdf", () => { + let pages; + + beforeAll(async () => { + pages = await loadAndWait("autoprint.pdf", ".endOfContent"); + }); + + afterAll(async () => { + await closePages(pages); + }); + + it("must check if printing is triggered when the document is open", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForFunction( + "window.PDFViewerApplication.scriptingReady === true" + ); + + await page.waitForFunction( + `document.querySelector(".printedPage") !== null` + ); + await page.keyboard.press("Escape"); + }) + ); + }); + }); }); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 68c603873..4439ffd3d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -563,3 +563,4 @@ !fields_order.pdf !issue15815.pdf !issue15818.pdf +!autoprint.pdf diff --git a/test/pdfs/autoprint.pdf b/test/pdfs/autoprint.pdf new file mode 100755 index 000000000..bc678d924 Binary files /dev/null and b/test/pdfs/autoprint.pdf differ