mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #11644 from Snuffleupagus/openAction
[api-minor] Add more general OpenAction support (PR 10334 follow-up, issue 11642)
This commit is contained in:
commit
aa3e5a2b8f
5 changed files with 117 additions and 97 deletions
52
web/app.js
52
web/app.js
|
@ -1033,11 +1033,9 @@ const PDFViewerApplication = {
|
|||
const pageModePromise = pdfDocument.getPageMode().catch(function() {
|
||||
/* Avoid breaking initial rendering; ignoring errors. */
|
||||
});
|
||||
const openActionDestPromise = pdfDocument
|
||||
.getOpenActionDestination()
|
||||
.catch(function() {
|
||||
/* Avoid breaking initial rendering; ignoring errors. */
|
||||
});
|
||||
const openActionPromise = pdfDocument.getOpenAction().catch(function() {
|
||||
/* Avoid breaking initial rendering; ignoring errors. */
|
||||
});
|
||||
|
||||
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
||||
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
||||
|
@ -1085,7 +1083,7 @@ const PDFViewerApplication = {
|
|||
storePromise,
|
||||
pageLayoutPromise,
|
||||
pageModePromise,
|
||||
openActionDestPromise,
|
||||
openActionPromise,
|
||||
])
|
||||
.then(
|
||||
async ([
|
||||
|
@ -1093,14 +1091,14 @@ const PDFViewerApplication = {
|
|||
values = {},
|
||||
pageLayout,
|
||||
pageMode,
|
||||
openActionDest,
|
||||
openAction,
|
||||
]) => {
|
||||
const viewOnLoad = AppOptions.get("viewOnLoad");
|
||||
|
||||
this._initializePdfHistory({
|
||||
fingerprint: pdfDocument.fingerprint,
|
||||
viewOnLoad,
|
||||
initialDest: openActionDest,
|
||||
initialDest: openAction && openAction.dest,
|
||||
});
|
||||
const initialBookmark = this.initialBookmark;
|
||||
|
||||
|
@ -1226,14 +1224,20 @@ const PDFViewerApplication = {
|
|||
);
|
||||
});
|
||||
|
||||
pagesPromise.then(() => {
|
||||
pagesPromise.then(async () => {
|
||||
if (!this.supportsPrinting) {
|
||||
return;
|
||||
}
|
||||
pdfDocument.getJavaScript().then(javaScript => {
|
||||
if (!javaScript) {
|
||||
return;
|
||||
}
|
||||
const [openAction, javaScript] = await Promise.all([
|
||||
openActionPromise,
|
||||
pdfDocument.getJavaScript(),
|
||||
]);
|
||||
let triggerAutoPrint = false;
|
||||
|
||||
if (openAction && openAction.action === "Print") {
|
||||
triggerAutoPrint = true;
|
||||
}
|
||||
if (javaScript) {
|
||||
javaScript.some(js => {
|
||||
if (!js) {
|
||||
// Don't warn/fallback for empty JavaScript actions.
|
||||
|
@ -1244,16 +1248,22 @@ const PDFViewerApplication = {
|
|||
return true;
|
||||
});
|
||||
|
||||
// Hack to support auto printing.
|
||||
for (const js of javaScript) {
|
||||
if (js && AutoPrintRegExp.test(js)) {
|
||||
setTimeout(function() {
|
||||
window.print();
|
||||
});
|
||||
return;
|
||||
if (!triggerAutoPrint) {
|
||||
// Hack to support auto printing.
|
||||
for (const js of javaScript) {
|
||||
if (js && AutoPrintRegExp.test(js)) {
|
||||
triggerAutoPrint = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (triggerAutoPrint) {
|
||||
setTimeout(function() {
|
||||
window.print();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onePageRendered.then(() => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue