From 2e65a92e04ccda779f1ca0caf1bd8fbfdef368b4 Mon Sep 17 00:00:00 2001 From: hailin Date: Fri, 26 Dec 2025 05:53:51 -0800 Subject: [PATCH] =?UTF-8?q?fix(planting-service):=20=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E6=8C=89=E6=AF=94=E4=BE=8B=E7=BC=A9=E6=94=BE?= =?UTF-8?q?=E5=88=B0=E5=90=88=E9=80=82=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 目标宽度 150pt(约 5cm) - 保持宽高比不变 - 避免签名图片过大 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../pdf/pdf-generator.service.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/backend/services/planting-service/src/infrastructure/pdf/pdf-generator.service.ts b/backend/services/planting-service/src/infrastructure/pdf/pdf-generator.service.ts index 59bda9f2..32eda333 100644 --- a/backend/services/planting-service/src/infrastructure/pdf/pdf-generator.service.ts +++ b/backend/services/planting-service/src/infrastructure/pdf/pdf-generator.service.ts @@ -388,25 +388,28 @@ export class PdfGeneratorService { const widget = widgets[0]; const rect = widget.getRectangle(); - // 获取签名图片原始尺寸 + // 获取签名图片原始尺寸并按比例缩放 const imgDims = signatureImage.scale(1); - const imgWidth = imgDims.width; - const imgHeight = imgDims.height; - // 直接在按钮位置绘制原始尺寸的签名图片 + // 目标宽度 150pt(约 5cm),保持宽高比 + const targetWidth = 150; + const scale = targetWidth / imgDims.width; + const scaledWidth = targetWidth; + const scaledHeight = imgDims.height * scale; + // 获取按钮所在的页面 const pages = pdfDoc.getPages(); const page = pages[5]; // 第6页(签名区域) - // 在按钮的左下角位置绘制签名图片(保持原始尺寸) + // 在按钮位置绘制缩放后的签名图片 page.drawImage(signatureImage, { x: rect.x, y: rect.y, - width: imgWidth, - height: imgHeight, + width: scaledWidth, + height: scaledHeight, }); - this.logger.log(`Signature embedded at (${rect.x}, ${rect.y}) with original size ${imgWidth}x${imgHeight}`); + this.logger.log(`Signature embedded at (${rect.x}, ${rect.y}) with size ${scaledWidth}x${scaledHeight}`); } else { throw new Error('No widgets found for signature button'); }