feat(11.1-02): add agentInitialsData param to preparePdf and embed at agent-initials fields
- Add agentInitialsData as 6th optional param (default null) - Embed agent initials PNG once before field loop (embed-once-draw-many pattern) - Add agent-initials branch in field loop: drawImage at field coordinates - Existing initials (client-initials) and agent-signature branches untouched
This commit is contained in:
@@ -24,6 +24,7 @@ export async function preparePdf(
|
||||
textFields: Record<string, string>,
|
||||
sigFields: SignatureFieldData[],
|
||||
agentSignatureData: string | null = null,
|
||||
agentInitialsData: string | null = null,
|
||||
): Promise<void> {
|
||||
const pdfBytes = await readFile(srcPath);
|
||||
const pdfDoc = await PDFDocument.load(pdfBytes);
|
||||
@@ -36,6 +37,12 @@ export async function preparePdf(
|
||||
agentSigImage = await pdfDoc.embedPng(agentSignatureData);
|
||||
}
|
||||
|
||||
// Embed agent initials image once — reused across all agent-initials fields
|
||||
let agentInitialsImage: PDFImage | null = null;
|
||||
if (agentInitialsData) {
|
||||
agentInitialsImage = await pdfDoc.embedPng(agentInitialsData);
|
||||
}
|
||||
|
||||
// Track which text field entries were successfully written via AcroForm so that
|
||||
// the fallback text stamp only shows entries that were NOT already embedded.
|
||||
const acroFilledKeys = new Set<string>();
|
||||
@@ -152,6 +159,17 @@ export async function preparePdf(
|
||||
});
|
||||
}
|
||||
// If no signature saved: the prepare route guards against this with 422 before calling preparePdf
|
||||
|
||||
} else if (fieldType === 'agent-initials') {
|
||||
if (agentInitialsImage) {
|
||||
page.drawImage(agentInitialsImage, {
|
||||
x: field.x,
|
||||
y: field.y,
|
||||
width: field.width,
|
||||
height: field.height,
|
||||
});
|
||||
}
|
||||
// If no initials saved: the prepare route guards against this with 422 before calling preparePdf
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user