Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFields() returns zero length array on fillable PDF #1620

Open
2 tasks done
stevehaneytrailblazer opened this issue Apr 25, 2024 · 1 comment
Open
2 tasks done

getFields() returns zero length array on fillable PDF #1620

stevehaneytrailblazer opened this issue Apr 25, 2024 · 1 comment

Comments

@stevehaneytrailblazer
Copy link

What were you trying to do?

I was attempting to perform a form fill on a PDF that appears to have many form fields on it. I can type into them in Adobe or when loading via a browser

However, when using the getForm() > getFields() functions there are no fields recognized.

How did you attempt to do it?

See sample code below in reproduce steps section. If you take the attached file and then run through similar code that should recreate.

Using version 1.17.1
ACORD-130-133-Forms.pdf

What actually happened?

Result is field count 0

What did you expect to happen?

I'm not sure why the fields aren't recognized or if maybe they're a different "type" of field.

How can we reproduce the issue?

import { PDFDocument } from "pdf-lib"
import fs from "node:fs";

async function index() {
    try {
        const inputFileName = "path of sample file downloaded locally";
        const inputFile = fs.readFileSync(inputFileName);
        const pdfDoc = await PDFDocument.load(inputFile);
        const form = pdfDoc.getForm();
        
        const fields = form.getFields();
        console.log('field count', fields.length);
        for(const field of fields) {
            const type = field.constructor.name
            const name = field.getName()
            console.log(`${type}: ${name}`)    
            for(const widget of field.acroField.getWidgets()) {
                console.log('rectangle', widget.getRectangle());
            }
        }
    }
    catch (err) { 
        console.error(`Unexpected failure ${err.message}`, err);
    }
}
index();

export default index;

Version

1.17.1

What environment are you running pdf-lib in?

Node

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

@sayo96
Copy link

sayo96 commented May 25, 2024

Is there any update on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants