Skip to content

Commit 82fc2c9

Browse files
committed
Include transfers correctly in the "GetOperatorList" message (PR 16588 follow-up)
Currently the transfers aren't actually being used with the "GetOperatorList" message, since the placement of the parameter is wrong; note the method signature: https://github.com/mozilla/pdf.js/blob/909a700afa004167bb05bc3d67ed113e74a71729/src/shared/message_handler.js#L219-L229 This goes back to PR 16588, which added the transfers parameter, and unfortunately we all missed that :-( Simply fixing the parameter isn't enough however, since that broke printing of Stamp-editors (and possibly others). The solution here is to *not* transfer data during printing, given that a single `PrintAnnotationStorage` instance is being used for all pages.
1 parent 3c43414 commit 82fc2c9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/display/annotation_storage.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,21 @@ class AnnotationStorage {
330330
* contents. (Necessary since printing is triggered synchronously in browsers.)
331331
*/
332332
class PrintAnnotationStorage extends AnnotationStorage {
333-
#serializable;
333+
#serializable = SerializableEmpty;
334334

335335
constructor(parent) {
336336
super();
337-
const { map, hash, transfer } = parent.serializable;
337+
338+
const { serializable } = parent;
339+
if (serializable === SerializableEmpty) {
340+
return;
341+
}
342+
const { map, hash, transfer } = serializable;
338343
// Create a *copy* of the data, since Objects are passed by reference in JS.
339344
const clone = structuredClone(map, transfer ? { transfer } : null);
340-
341-
this.#serializable = { map: clone, hash, transfer };
345+
// The `PrintAnnotationStorage` instance is re-used for all pages,
346+
// hence we cannot transfer the data since that breaks printing.
347+
this.#serializable = { map: clone, hash, transfer: [] };
342348
}
343349

344350
/**

src/display/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ class PDFPageProxy {
18981898
annotationStorage: map,
18991899
modifiedIds,
19001900
},
1901+
/* queueingStrategy = */ undefined,
19011902
transfer
19021903
);
19031904
const reader = readableStream.getReader();

test/driver.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,10 @@ class Driver {
803803
}
804804

805805
task.pdfDoc = doc;
806+
if (!task.save && task.print && task.annotationStorage) {
807+
doc.annotationStorage._setValues(task.annotationStorage);
808+
task.printAnnotationStorage = doc.annotationStorage.print;
809+
}
806810
task.optionalContentConfigPromise = doc.getOptionalContentConfig({
807811
intent: task.print ? "print" : "display",
808812
});
@@ -969,7 +973,7 @@ class Driver {
969973
pageColors = null,
970974
partialCrop = null;
971975

972-
if (task.annotationStorage) {
976+
if (!task.print && task.annotationStorage) {
973977
task.pdfDoc.annotationStorage._setValues(task.annotationStorage);
974978
}
975979

@@ -1079,6 +1083,8 @@ class Driver {
10791083
} else if (renderPrint) {
10801084
if (task.annotationStorage) {
10811085
renderContext.annotationMode = AnnotationMode.ENABLE_STORAGE;
1086+
renderContext.printAnnotationStorage =
1087+
task.printAnnotationStorage;
10821088
}
10831089
renderContext.intent = "print";
10841090
}

0 commit comments

Comments
 (0)