fix(planting-service): 签名图片按比例缩放到合适大小
- 目标宽度 150pt(约 5cm) - 保持宽高比不变 - 避免签名图片过大 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6c017d2086
commit
2e65a92e04
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue