1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

JS -- Implement doc object

* https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_api_reference.pdf#page=335
 * it has all the properties/methods defined in the spec
 * unimplemented methods are there but with an empty body to avoid exception when calling an undefined method
 * implement zoom, zoomType, layout, pageNum, ...
This commit is contained in:
Calixte Denizet 2020-11-05 13:22:35 +01:00
parent 1c17e078ec
commit 8de98079ca
5 changed files with 1172 additions and 15 deletions

View file

@ -1350,11 +1350,11 @@ const PDFViewerApplication = {
);
this._idleCallbacks.add(callback);
}
this._initializeJavaScript(pdfDocument);
});
this._initializePageLabels(pdfDocument);
this._initializeMetadata(pdfDocument);
this._initializeJavaScript(pdfDocument);
},
/**
@ -1370,25 +1370,46 @@ const PDFViewerApplication = {
return;
}
const scripting = this.externalServices.scripting;
const {
info,
metadata,
contentDispositionFilename,
} = await pdfDocument.getMetadata();
window.addEventListener("updateFromSandbox", function (event) {
window.addEventListener("updateFromSandbox", event => {
const detail = event.detail;
const id = detail.id;
if (!id) {
switch (detail.command) {
case "println":
console.log(detail.value);
break;
case "clear":
console.clear();
break;
case "alert":
// eslint-disable-next-line no-alert
window.alert(detail.value);
break;
case "clear":
console.clear();
break;
case "error":
console.error(detail.value);
break;
case "layout":
this.pdfViewer.spreadMode = apiPageLayoutToSpreadMode(detail.value);
return;
case "page-num":
this.pdfViewer.currentPageNumber = detail.value + 1;
return;
case "print":
this.triggerPrinting();
return;
case "println":
console.log(detail.value);
break;
case "zoom":
if (typeof detail.value === "string") {
this.pdfViewer.currentScaleValue = detail.value;
} else {
this.pdfViewer.currentScale = detail.value;
}
return;
}
return;
}
@ -1411,7 +1432,23 @@ const PDFViewerApplication = {
const dispatchEventName = generateRandomStringForSandbox(objects);
const calculationOrder = [];
scripting.createSandbox({ objects, dispatchEventName, calculationOrder });
const { length } = await pdfDocument.getDownloadInfo();
const filename =
contentDispositionFilename || getPDFFileNameFromURL(this.url);
scripting.createSandbox({
objects,
dispatchEventName,
calculationOrder,
docInfo: {
...info,
baseURL: this.baseUrl,
filesize: length,
filename,
metadata,
numPages: pdfDocument.numPages,
URL: this.url,
},
});
},
/**