Cannot replace a form value, for a form field, where multiple occurrences of the form field exist
See original GitHub issueHey @Hopding,
Thank you for the awesome repository, it has been really useful.
I’ve created a demo using pdf-lib to fill out form fields in an AcroForm PDF to look to alternatives to an existing solution using iTextPDF. The functions have come from examples in some of the other issues, and would actually be quite nice exposed as part of the pdflib api! 😃 Happy to help do this, as I think it would be really useful!
Issue:- Cannot replace a form value, for a form field, where multiple occurrences of the form field exist
Expected Behaviour:- A single name reference can be provided, and this value is used to fill in all form fields matching that name reference.
Actual Behaviour:- An exception is thrown where we have two fields with the same name, as they are referenced as instalments#0 & instalments#1 in the adobe form
Error: Expected instance of PDFArray, but got instance of undefined
Steps to reproduce:-
I have created a minimal example here - https://github.com/YOU54F/pdf-form-node
It contains a test.pdf with 3 form fields.
Filling in a form field, where it only exists once in a document
To run:
npm install
npm run single
- Reads the
test.pdftemplate and outputs asfilled_single.pdf. - QPDF is called to correct
filled_single.pdfand outputs asfixed_single.pdf
Filling in a form field, where it exists more once in a document
To run:
npm install
npm run multiple
- Reads the
test.pdftemplate and outputs asfilled_multiple.pdf. - QPDF is called to correct
filled_multiple.pdfand outputs asfixed_multiple.pdf
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)

Top Related StackOverflow Question
pdf-libnow has form creation and filling APIs that should be used instead of the above example(s). See the form filling JSFiddle for a working example. Additional information is available in the README and API docs. ThePDFTextField.setTextmethod is of particular relevance to this issue.Thanks again @Hopding ! Look forward to trying this out 👍🏽