|
|
@@ -1513,13 +1513,13 @@ export class CanvasPhotoEditor {
|
|
|
try {
|
|
|
this.isHistory = false;
|
|
|
const DPR = 3;
|
|
|
-
|
|
|
+ const mmToPx = 96 / 25.4;
|
|
|
const rules = {
|
|
|
- a4: { perSheet: 1, orient: "portrait", format: "a4" },
|
|
|
- a3: { perSheet: 2, orient: "landscape", format: "a3" },
|
|
|
- four: { perSheet: 4, orient: "landscape", format: [728, 297] },
|
|
|
+ a4: { perSheet: 1, orient: "portrait", format: "a4", bindingMargin: 28*mmToPx },
|
|
|
+ a3: { perSheet: 2, orient: "landscape", format: "a3", bindingMargin: 28*2*mmToPx },
|
|
|
+ four: { perSheet: 4, orient: "landscape", format: [728, 297], bindingMargin: 0 },
|
|
|
};
|
|
|
- const { perSheet, orient, format } = rules[paperType];
|
|
|
+ const { perSheet, orient, format, bindingMargin } = rules[paperType];
|
|
|
const pdf = new jsPDF({ orientation: orient, unit: "mm", format });
|
|
|
const pdfW = pdf.internal.pageSize.getWidth();
|
|
|
const pdfH = pdf.internal.pageSize.getHeight();
|
|
|
@@ -1621,9 +1621,9 @@ export class CanvasPhotoEditor {
|
|
|
// PDF 位置
|
|
|
let x, y, w, h;
|
|
|
if (paperType === "a4") {
|
|
|
- [x, y, w, h] = [0, 0, pdfW, pdfH];
|
|
|
+ [x, y, w, h] = [0 + 28, 0, pdfW-28, pdfH];
|
|
|
} else if (paperType === "a3") {
|
|
|
- w = pdfW / 2; h = pdfH; x = idxInSheet * w; y = 0;
|
|
|
+ w = ((pdfW / 2) - 28); h = pdfH; x = (idxInSheet * w)+56; y = 0;
|
|
|
} else {
|
|
|
w = pdfW / 4; h = pdfH;
|
|
|
x = idxInSheet * w;
|
|
|
@@ -1690,14 +1690,16 @@ export class CanvasPhotoEditor {
|
|
|
// if (paperType === "four") {
|
|
|
// pageWidth = pageWidth * (724 / 840)
|
|
|
// }
|
|
|
- pageCanvas.width = pageWidth * DPR * (paperType === "a3" ? 2 : paperType === "a4" ? 1 : 4);
|
|
|
+ const mmToPx = 96 / 25.4;
|
|
|
+ const bindingMargin = (paperType === "a3" ? 56 : paperType === "a4" ? 28 : 0) * DPR * mmToPx; // mm
|
|
|
+ const pageWith = pageWidth * DPR * (paperType === "a3" ? 2 : paperType === "a4" ? 1 : 4);
|
|
|
+ pageCanvas.width = pageWith + bindingMargin
|
|
|
pageCanvas.height = this.pageHeight * DPR * 1;
|
|
|
const ctx = pageCanvas.getContext("2d");
|
|
|
ctx.scale(DPR, DPR);
|
|
|
-
|
|
|
// 白色背景
|
|
|
ctx.fillStyle = "#fff";
|
|
|
- ctx.fillRect(0, 0, pageCanvas.width, pageCanvas.height);
|
|
|
+ ctx.fillRect(0, 0, pageCanvas.width + bindingMargin, pageCanvas.height);
|
|
|
|
|
|
// 绘制本组页面
|
|
|
group.forEach((page, idxInSheet) => {
|
|
|
@@ -1781,13 +1783,24 @@ export class CanvasPhotoEditor {
|
|
|
// ==========================================
|
|
|
// 🔥 1:1 还原你原 drawGuideLine 标引逻辑
|
|
|
// ==========================================
|
|
|
- this.renderIndexList(ctx, pageIndex, false)
|
|
|
+ this.renderIndexList(ctx, pageIndex, true)
|
|
|
|
|
|
ctx.restore();
|
|
|
});
|
|
|
-
|
|
|
// 转图片并加入 ZIP
|
|
|
- const base64 = pageCanvas.toDataURL("image/jpeg");
|
|
|
+ // ========= 加在这里 =========
|
|
|
+
|
|
|
+ const newCanvas = document.createElement('canvas');
|
|
|
+ newCanvas.width = pageCanvas.width;
|
|
|
+ newCanvas.height = pageCanvas.height;
|
|
|
+ const ctxs = newCanvas.getContext('2d');
|
|
|
+ ctxs.fillStyle = '#fff';
|
|
|
+ ctxs.fillRect(0,0, newCanvas.width, newCanvas.height);
|
|
|
+ ctxs.drawImage(pageCanvas, bindingMargin, 0);
|
|
|
+
|
|
|
+ // 导出用 newCanvas
|
|
|
+ const base64 = newCanvas.toDataURL('image/jpeg');
|
|
|
+ // const base64 = pageCanvas.toDataURL("image/jpeg");
|
|
|
zip.file(`第${groupIndex + 1}张.jpg`, base64.split(",")[1], { base64: true });
|
|
|
}
|
|
|
|