question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot replace a form value, for a form field, where multiple occurrences of the form field exist

See original GitHub issue

Hey @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.

Screenshot 2020-05-18 at 19 01 16

Filling in a form field, where it only exists once in a document

To run:

npm install
npm run single
  • Reads the test.pdf template and outputs as filled_single.pdf.
  • QPDF is called to correct filled_single.pdf and outputs as fixed_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.pdf template and outputs as filled_multiple.pdf.
  • QPDF is called to correct filled_multiple.pdf and outputs as fixed_multiple.pdf

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Hopdingcommented, Sep 16, 2020

pdf-lib now 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. The PDFTextField.setText method is of particular relevance to this issue.

0reactions
YOU54Fcommented, Sep 16, 2020

Thanks again @Hopding ! Look forward to trying this out 👍🏽

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manually Set Value for FormBuilder Control - Stack Overflow
I would just use ngControl="dept" on the form element, like I'm doing with the rest of the form but its a custom directive/component....
Read more >
Using Lookup and multivalued fields in queries
Click the Lookup field, and then on the Design tab, in the Show/Hide group, click Property Sheet. In this example, use the NEState...
Read more >
Overview of the SQL REPLACE function - SQLShack
REPLACEment : REPLACEs the specified string or character value of the given expression. Note: The SQL REPLACE function performs comparisons based ...
Read more >
Form fields - Django documentation
Since all Field subclasses have required=True by default, the validation condition here is important. If you want to include a boolean in your...
Read more >
Chapter 18 Forms and Form Fields - Eloquent JavaScript
Multiline text fields have their own tag, <textarea> , mostly because using an attribute to specify a multiline starting value would be awkward....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found