This commit is contained in:
2026-03-10 19:15:54 +08:00
parent 1bcb4a9c2e
commit c5970da195

View File

@@ -2113,13 +2113,17 @@
} }
html2canvas(pageEl, { html2canvas(pageEl, {
scale: 2, scale: 1.5,
useCORS: true, useCORS: true,
scrollX: 0, scrollX: 0,
scrollY: -window.scrollY, scrollY: -window.scrollY,
}) })
.then(function (canvas) { .then(function (canvas) {
var imgData = canvas.toDataURL("image/png"); // 使用 JPEG 可以避免部分环境下 PNG 解析问题Incomplete or corrupt PNG file
var imgData = canvas.toDataURL(
"image/jpeg",
0.95,
);
var pdf = new jspdf.jsPDF("p", "mm", "a4"); var pdf = new jspdf.jsPDF("p", "mm", "a4");
var pageWidth = pdf.internal.pageSize.getWidth(); var pageWidth = pdf.internal.pageSize.getWidth();
@@ -2134,7 +2138,7 @@
pdf.addImage( pdf.addImage(
imgData, imgData,
"PNG", "JPEG",
0, 0,
position, position,
imgWidth, imgWidth,
@@ -2147,7 +2151,7 @@
pdf.addPage(); pdf.addPage();
pdf.addImage( pdf.addImage(
imgData, imgData,
"PNG", "JPEG",
0, 0,
position, position,
imgWidth, imgWidth,