diff --git a/public/PDF/Template-EDV-ERT_v4.1.pdf b/public/PDF/Template-EDV-ERT_v4.1.pdf new file mode 100644 index 0000000..466768a Binary files /dev/null and b/public/PDF/Template-EDV-ERT_v4.1.pdf differ diff --git a/public/js/libProcessScript.js b/public/js/libProcessScript.js index b18c371..ebb4492 100644 --- a/public/js/libProcessScript.js +++ b/public/js/libProcessScript.js @@ -21,6 +21,9 @@ const dd = createDebugLogger(true, "dd"); // code function at bottom of the page // Wrapper function to fetch, update, and download PDF async function processAndDownloadPdf(filePath, ...dataSources) { + + dd(`Loaded PDF Template: ${filePath.value}`) + try { const pdfBytes = await fetchPdfBytes(filePath); const updatedPdfBytes = await updatePdfFields(pdfBytes, dataSources); @@ -56,26 +59,30 @@ async function updatePdfFields( dataSources, skipMissingFields = true ) { + console.log("Datasource size:", dataSources.length) try { const pdfDoc = await PDFLib.PDFDocument.load(pdfBytes); const form = pdfDoc.getForm(); dataSources.forEach((dataSource) => { + console.log("Current Datasource", dataSource) dataSource.forEach((record) => { - Object.entries(record).forEach(([fieldName, fieldValue]) => { + console.log("Working in: ", record) + Object.entries(record).forEach(([fieldName, fieldValue]) => { + dd(`Field: ${fieldName} Value: ${fieldValue}`) //debugger try { const formField = form.getTextField(fieldName); if (formField) { - console.info(`Field "${fieldName}" OK`); - dd(fieldName, "-->", fieldValue); + // console.info(`Field "${fieldName}" OK`); + dd(`${fieldName} --> ${fieldValue} OK`); formField.setText(String(fieldValue)); } else if (!skipMissingFields) { //dd(`Skipping Field: ${fieldName} NOT FOUND`) console.warn(`Field "${fieldName}" not found.`); } } catch (err) { - console.error(`Error updating field "${fieldName}":`, err); + console.error(`Error updating field "${fieldName}":`); //console.error(`Error updating field "${fieldName}":`, err); } }); }); diff --git a/public/listFields.html b/public/listFields.html new file mode 100644 index 0000000..887740e --- /dev/null +++ b/public/listFields.html @@ -0,0 +1,10 @@ + + +
+ +| $id | +Db full name | +Db license number | +Db state name | +Db employee | +
|---|---|---|---|---|
| + | + | + | + | + |