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:
commit
037c181af6
1 changed files with 15 additions and 12 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue