Can't get child field font in pdf-lib.js

170 Views Asked by At

I am trying to get a list of fields and which fonts are assigned to them. I can use form.getFields() to get a list of fields in the form. I can then run through the "dict" to find the font name - Easy!

Ex1

However, when I am working with a field that has "Child Fields", for example, a pdf with text fields of the same name, it does not have this font parameter.

It only has "/Kids" which contains some sort of reference I haven't been able to understand

Ex2

I have also tried this:

createPDFAcroFields(fields\[1\].acroField.Kids())

However, it returns a blank array. Any help would be greatly appreciated.

Here's a jsFidle that grabs the fields and can show you the objects that are missing the font in the console!

https://jsfiddle.net/xek1stmz/13/

<html>
  <head>
    <meta charset="utf-8" />
    <script src="https://unpkg.com/pdf-lib/dist/pdf-lib.min.js"></script>
  </head>

  <script>
    const { PDFDocument } = PDFLib

    async function getFieldFonts() {

        // Fetch the PDF with form fields
      const formUrl = 'https://partners.metas.global/Code39.pdf'
      const formPdfBytes = await fetch(formUrl).then(res => res.arrayBuffer())

      // Load a PDF with form fields
      const pdfDoc = await PDFDocument.load(formPdfBytes)
      
      // Get the form containing all the fields
      form = pdfDoc.getForm();
      fields = form.getFields();

      console.log(fields);

    }

    getFieldFonts();
  </script>
</html>

0

There are 0 best solutions below