1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18644 from Snuffleupagus/PDFPrintService-unconditional-toBlob

Use `HTMLCanvasElement.toBlob()` unconditionally in `PDFPrintService`
This commit is contained in:
Tim van der Meij 2024-08-23 20:37:46 +02:00 committed by GitHub
commit 037c181af6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -190,24 +190,27 @@ class PDFPrintService {
useRenderedPage() {
this.throwIfInactive();
const img = document.createElement("img");
const scratchCanvas = this.scratchCanvas;
if ("toBlob" in scratchCanvas) {
scratchCanvas.toBlob(function (blob) {
img.src = URL.createObjectURL(blob);
});
} else {
img.src = scratchCanvas.toDataURL();
}
this.scratchCanvas.toBlob(blob => {
img.src = URL.createObjectURL(blob);
});
const wrapper = document.createElement("div");
wrapper.className = "printedPage";
wrapper.append(img);
this.printContainer.append(wrapper);
return new Promise(function (resolve, reject) {
img.onload = resolve;
img.onerror = reject;
});
const { promise, resolve, reject } = Promise.withResolvers();
img.onload = resolve;
img.onerror = reject;
promise
.catch(() => {
// Avoid "Uncaught promise" messages in the console.
})
.then(() => {
URL.revokeObjectURL(img.src);
});
return promise;
}
performPrint() {