forked from yogesh073/node-pdfLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.js
More file actions
23 lines (22 loc) · 810 Bytes
/
template.js
File metadata and controls
23 lines (22 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const { PDFDocument } = require("pdf-lib")
const fs = require('fs');
const createPDF = async () => {
try {
const pdfDoc = await PDFDocument.load(fs.readFileSync(`./template/template.pdf`), {
ignoreEncryption: true,
throwOnInvalidObject: true,
});
const form = pdfDoc.getForm();
let fieldNames = pdfDoc.getForm().getFields();
fieldNames = fieldNames.map(f => f.getName())
console.log(fieldNames)
let coiIndex = fieldNames.indexOf('connectionLink')
if (coiIndex >= 0) {
form.getTextField(fieldNames[coiIndex]).setText('https://www.appgambit.com/')
}
fs.writeFileSync("./template/template-output.pdf", await pdfDoc.save());
} catch (error) {
console.log(error)
}
}
createPDF()