mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-30 12:06:46 +00:00
修复 pdf无法打印问题 修复pdf打印添加水印问题
This commit is contained in:
@@ -13874,7 +13874,7 @@ class PDFPrintService {
|
|||||||
};
|
};
|
||||||
return new Promise(renderNextPage);
|
return new Promise(renderNextPage);
|
||||||
}
|
}
|
||||||
useRenderedPage() {
|
useRenderedPage() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
this.scratchCanvas.toBlob(blob => {
|
this.scratchCanvas.toBlob(blob => {
|
||||||
@@ -13883,28 +13883,29 @@ class PDFPrintService {
|
|||||||
const wrapper = document.createElement("div");
|
const wrapper = document.createElement("div");
|
||||||
wrapper.className = "printedPage";
|
wrapper.className = "printedPage";
|
||||||
wrapper.append(img);
|
wrapper.append(img);
|
||||||
var printWatermarkDiv = document.createElement('div');
|
|
||||||
// console.log(pageSize);
|
// 关键:定义 pageSize 和 pageCount
|
||||||
|
const pageSize = this.pagesOverview[0];
|
||||||
|
const pageCount = this.pagesOverview.length;
|
||||||
|
|
||||||
|
var printWatermarkDiv = document.createElement('div');
|
||||||
printWatermarkDiv.style.position = 'absolute';
|
printWatermarkDiv.style.position = 'absolute';
|
||||||
printWatermarkDiv.style.left = '0px';
|
printWatermarkDiv.style.left = '0px';
|
||||||
printWatermarkDiv.style.top = '0px';
|
printWatermarkDiv.style.top = '0px';
|
||||||
printWatermarkDiv.style.width = '1024px';
|
printWatermarkDiv.style.width = '1024px';
|
||||||
printWatermarkDiv.style.height = pageSize.height*pageCount+ "px";
|
printWatermarkDiv.style.height = pageSize.height * pageCount + "px";
|
||||||
watermarkObj(printWatermarkDiv,watermarkTxt);
|
watermarkObj(printWatermarkDiv, watermarkTxt);
|
||||||
wrapper.appendChild(printWatermarkDiv);
|
wrapper.appendChild(printWatermarkDiv);
|
||||||
this.printContainer.append(wrapper);
|
this.printContainer.append(wrapper);
|
||||||
const {
|
|
||||||
promise,
|
const { promise, resolve, reject } = Promise.withResolvers();
|
||||||
resolve,
|
|
||||||
reject
|
|
||||||
} = Promise.withResolvers();
|
|
||||||
img.onload = resolve;
|
img.onload = resolve;
|
||||||
img.onerror = reject;
|
img.onerror = reject;
|
||||||
promise.catch(() => {}).then(() => {
|
promise.catch(() => {}).then(() => {
|
||||||
URL.revokeObjectURL(img.src);
|
URL.revokeObjectURL(img.src);
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
performPrint() {
|
performPrint() {
|
||||||
this.throwIfInactive();
|
this.throwIfInactive();
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|||||||
@@ -78,13 +78,6 @@
|
|||||||
}
|
}
|
||||||
window.location.href = href;
|
window.location.href = href;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 水印初始化(保持原有逻辑)
|
|
||||||
window.onload = function () {
|
|
||||||
if (typeof initWaterMark === 'function') {
|
|
||||||
initWaterMark();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user