Skip to main content

pdf-lib node package for manipulate pdf template

 use pdf-lib to fill in pdf template:

export const fillForm = async (pdfDoc: any, fieldNames: string[], fieldValues: string[]) => {

  const form = pdfDoc.context.lookup(pdfDoc.catalog.get(PDFName.of('AcroForm')))

  if (!form) {

    throw new Error('PDF does not contain a form')


  form.set(PDFName.of('NeedAppearances'), PDFBool.True)

  const fieldRefs = form.context.lookup(form.get(PDFName.of('Fields')))

  if (!fieldRefs) {

    throw new Error('PDF form does not contain any fields')


  const fields = any) => form.context.lookup(ref))

  fields.forEach((field: any) => {

    const name = field.get(PDFName.of('T'))

    console.log('pdf form fieldName:', name, name.value)

    if (name) {

      const idx = fieldNames.indexOf(name.value)

      const newValue = idx >= 0 ? fieldValues[idx] : '' 

      if (newValue) {

        field.set(PDFName.of('V'), PDFString.of(newValue))

        field.set(PDFName.of('Ff'), PDFNumber.of(1))





another good code:


Popular posts from this blog

About GraphQL - Downside

Web caching complexity

File uploading. Since GraphQL doesn’t understand files, a file uploading feature is not included in its specification. You won’t have to deal with this limitation in case of REST, as there you can POST or PUT whatever content you want to.
To allow file uploads in your GraphQL web app, there are several options: using Base64 encoding. But it will make the request larger and expensive to encode/decode.making a separate API endpoint just for this purpose.using a library like Apollo for implementing the GraphQL multipart request specification.uploadFileToS3:combineResolvers( // isAuthenticated, async (parent, args, { models }) => { const { file } = awaitargs const { createReadStream, filename, mimetype, encoding } = awaitfile conststream = createReadStream() constresult = awaituploadFileToS3(filename, stream) returnresult } ),