[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:
Jonas Jenwald 2022-06-13 13:35:58 +02:00
parent c5dc082da4
commit 1cc7cecc7b
6 changed files with 196 additions and 41 deletions

View file

@ -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
);
},
};