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'); }