mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +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() {
|
useRenderedPage() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
const scratchCanvas = this.scratchCanvas;
|
this.scratchCanvas.toBlob(blob => {
|
||||||
if ("toBlob" in scratchCanvas) {
|
img.src = URL.createObjectURL(blob);
|
||||||
scratchCanvas.toBlob(function (blob) {
|
});
|
||||||
img.src = URL.createObjectURL(blob);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
img.src = scratchCanvas.toDataURL();
|
|
||||||
}
|
|
||||||
|
|
||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
wrapper.className = "printedPage";
|
wrapper.className = "printedPage";
|
||||||
wrapper.append(img);
|
wrapper.append(img);
|
||||||
this.printContainer.append(wrapper);
|
this.printContainer.append(wrapper);
|
||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
const { promise, resolve, reject } = Promise.withResolvers();
|
||||||
img.onload = resolve;
|
img.onload = resolve;
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
});
|
|
||||||
|
promise
|
||||||
|
.catch(() => {
|
||||||
|
// Avoid "Uncaught promise" messages in the console.
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
URL.revokeObjectURL(img.src);
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
performPrint() {
|
performPrint() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue