fix(planting): center signature image on the signature field

Calculate signature position based on field center instead of left-bottom
corner, so the signature image is properly centered within the field area.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-04 00:00:13 -08:00
parent f0f44aeb39
commit f5afb65df8
1 changed files with 14 additions and 5 deletions

View File

@ -395,8 +395,10 @@ export class PdfGeneratorService {
const signatureImage = await pdfDoc.embedPng(signature.signatureImagePng);
// 获取签名字段位置作为参考
let signatureX = 380; // 默认 x 坐标
let signatureY = 100; // 默认 y 坐标
let fieldX = 380; // 默认 x 坐标
let fieldY = 100; // 默认 y 坐标
let fieldWidth = 92;
let fieldHeight = 51;
try {
const form = pdfDoc.getForm();
@ -404,9 +406,10 @@ export class PdfGeneratorService {
const widgets = signatureButton.acroField.getWidgets();
if (widgets.length > 0) {
const rect = widgets[0].getRectangle();
// 使用字段左下角作为签名位置参考
signatureX = rect.x;
signatureY = rect.y;
fieldX = rect.x;
fieldY = rect.y;
fieldWidth = rect.width;
fieldHeight = rect.height;
this.logger.log(`Signature field position: x=${rect.x}, y=${rect.y}, field size: ${rect.width}x${rect.height}`);
}
} catch {
@ -433,6 +436,12 @@ export class PdfGeneratorService {
scaledWidth = (width * maxHeight) / height;
}
// 计算签名位置:以签名字段中心为基准,将签名图片居中放置
const fieldCenterX = fieldX + fieldWidth / 2;
const fieldCenterY = fieldY + fieldHeight / 2;
const signatureX = fieldCenterX - scaledWidth / 2;
const signatureY = fieldCenterY - scaledHeight / 2;
// 在签名位置绘制图片
lastPage.drawImage(signatureImage, {
x: signatureX,