mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
[api-minor] Introduce a PrintAnnotationStorage
with *frozen* serializable data
Given that printing is triggered *synchronously* in browsers, it's thus possible for scripting (in PDF documents) to modify the Annotation-data while printing is currently ongoing. To work-around that we add a new printing-specific `AnnotationStorage`, where the serializable data is *frozen* upon initialization, which the viewer can thus create/utilize during printing.
This commit is contained in:
parent
c5dc082da4
commit
1cc7cecc7b
6 changed files with 196 additions and 41 deletions
|
@ -29,7 +29,8 @@ function composePage(
|
|||
size,
|
||||
printContainer,
|
||||
printResolution,
|
||||
optionalContentConfigPromise
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStoragePromise
|
||||
) {
|
||||
const canvas = document.createElement("canvas");
|
||||
|
||||
|
@ -61,9 +62,12 @@ function composePage(
|
|||
ctx.restore();
|
||||
|
||||
let thisRenderTask = null;
|
||||
pdfDocument
|
||||
.getPage(pageNumber)
|
||||
.then(function (pdfPage) {
|
||||
|
||||
Promise.all([
|
||||
pdfDocument.getPage(pageNumber),
|
||||
printAnnotationStoragePromise,
|
||||
])
|
||||
.then(function ([pdfPage, printAnnotationStorage]) {
|
||||
if (currentRenderTask) {
|
||||
currentRenderTask.cancel();
|
||||
currentRenderTask = null;
|
||||
|
@ -75,6 +79,7 @@ function composePage(
|
|||
intent: "print",
|
||||
annotationMode: AnnotationMode.ENABLE_STORAGE,
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStorage,
|
||||
};
|
||||
currentRenderTask = thisRenderTask = pdfPage.render(renderContext);
|
||||
return thisRenderTask.promise;
|
||||
|
@ -114,7 +119,8 @@ function FirefoxPrintService(
|
|||
pagesOverview,
|
||||
printContainer,
|
||||
printResolution,
|
||||
optionalContentConfigPromise = null
|
||||
optionalContentConfigPromise = null,
|
||||
printAnnotationStoragePromise = null
|
||||
) {
|
||||
this.pdfDocument = pdfDocument;
|
||||
this.pagesOverview = pagesOverview;
|
||||
|
@ -122,6 +128,8 @@ function FirefoxPrintService(
|
|||
this._printResolution = printResolution || 150;
|
||||
this._optionalContentConfigPromise =
|
||||
optionalContentConfigPromise || pdfDocument.getOptionalContentConfig();
|
||||
this._optionalContentConfigPromise =
|
||||
printAnnotationStoragePromise || Promise.resolve();
|
||||
}
|
||||
|
||||
FirefoxPrintService.prototype = {
|
||||
|
@ -132,6 +140,7 @@ FirefoxPrintService.prototype = {
|
|||
printContainer,
|
||||
_printResolution,
|
||||
_optionalContentConfigPromise,
|
||||
_printAnnotationStoragePromise,
|
||||
} = this;
|
||||
|
||||
const body = document.querySelector("body");
|
||||
|
@ -149,7 +158,8 @@ FirefoxPrintService.prototype = {
|
|||
pagesOverview[i],
|
||||
printContainer,
|
||||
_printResolution,
|
||||
_optionalContentConfigPromise
|
||||
_optionalContentConfigPromise,
|
||||
_printAnnotationStoragePromise
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -175,14 +185,16 @@ PDFPrintServiceFactory.instance = {
|
|||
pagesOverview,
|
||||
printContainer,
|
||||
printResolution,
|
||||
optionalContentConfigPromise
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStoragePromise
|
||||
) {
|
||||
return new FirefoxPrintService(
|
||||
pdfDocument,
|
||||
pagesOverview,
|
||||
printContainer,
|
||||
printResolution,
|
||||
optionalContentConfigPromise
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStoragePromise
|
||||
);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue