Skip to content

Commit

Permalink
Merge pull request #18644 from Snuffleupagus/PDFPrintService-uncondit…
Browse files Browse the repository at this point in the history
…ional-toBlob

Use `HTMLCanvasElement.toBlob()` unconditionally in `PDFPrintService`
  • Loading branch information
timvandermeij authored Aug 23, 2024
2 parents f11baea + 6a1b1ae commit 037c181
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 037c181

Please sign in to comment.