mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[api-minor] Add more general OpenAction support (PR 10334 follow-up, issue 11642)
This patch deprecates the existing `getOpenActionDestination` API method, in favor of a better and more general `getOpenAction` method instead. (For now JavaScript actions, related to printing, are still handled as before.) By clearly separating "regular" Print actions from the JavaScript handling, it's thus possible to get rid of the somewhat annoying and strictly incorrect warning when the viewer loads.
This commit is contained in:
parent
25693c6b6d
commit
01fb309a2a
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);
|
||||
|
@ -1087,7 +1085,7 @@ const PDFViewerApplication = {
|
|||
storePromise,
|
||||
pageLayoutPromise,
|
||||
pageModePromise,
|
||||
openActionDestPromise,
|
||||
openActionPromise,
|
||||
])
|
||||
.then(
|
||||
async ([
|
||||
|
@ -1095,14 +1093,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;
|
||||
|
||||
|
@ -1228,14 +1226,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.
|
||||
|
@ -1246,16 +1250,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