From fae1cf1b68006c57d86ccc165da7930951c297d5 Mon Sep 17 00:00:00 2001 From: Chandler Copeland Date: Sat, 21 Mar 2026 15:02:51 -0600 Subject: [PATCH] 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 --- .../src/lib/pdf/prepare-document.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/teressa-copeland-homes/src/lib/pdf/prepare-document.ts b/teressa-copeland-homes/src/lib/pdf/prepare-document.ts index b2bae4c..bb7c72d 100644 --- a/teressa-copeland-homes/src/lib/pdf/prepare-document.ts +++ b/teressa-copeland-homes/src/lib/pdf/prepare-document.ts @@ -24,6 +24,7 @@ export async function preparePdf( textFields: Record, sigFields: SignatureFieldData[], agentSignatureData: string | null = null, + agentInitialsData: string | null = null, ): Promise { 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(); @@ -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 } }