From 458d3f9b649eb1cbace9b6631eef796ccdaa7d79 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 31 Jan 2026 10:09:29 +0000 Subject: [PATCH] fix: Implement fillPdf function that was returning empty array The fillPdf function was a stub that returned an empty Uint8Array. Implemented proper PDF form filling using pdf-lib to handle both text fields and checkboxes. https://claude.ai/code/session_01SYhhaVHw6we1P6Y2kqLnDe --- services/pdfService.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/services/pdfService.ts b/services/pdfService.ts index b26e658..efba917 100644 --- a/services/pdfService.ts +++ b/services/pdfService.ts @@ -100,5 +100,36 @@ export const createFilledPdf = async (base64: string, fields: ExtractedField[], }; export const fillPdf = async (base64: string, fieldValues: Record): Promise => { - return new Uint8Array(); + const pdfDoc = await PDFDocument.load(base64); + + try { + const form = pdfDoc.getForm(); + + for (const [fieldName, value] of Object.entries(fieldValues)) { + try { + const field = form.getField(fieldName); + if (!field) continue; + + if (field instanceof PDFTextField) { + field.setText(String(value)); + } else if (field instanceof PDFCheckBox) { + const isChecked = typeof value === 'boolean' + ? value + : String(value).toLowerCase() === 'true' || String(value).toLowerCase() === 'yes'; + if (isChecked) { + field.check(); + } else { + field.uncheck(); + } + } + } catch (e) { + // Field might be read-only or have other issues - continue with other fields + console.warn(`Could not fill field "${fieldName}":`, e); + } + } + } catch (e) { + console.warn("Error filling form fields:", e); + } + + return await pdfDoc.save(); };