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

Add support for AcroForm textFields with same fieldName #3361

Open
imjosh opened this issue Jan 13, 2022 · 2 comments · May be fixed by #3821
Open

Add support for AcroForm textFields with same fieldName #3361

imjosh opened this issue Jan 13, 2022 · 2 comments · May be fixed by #3821

Comments

@imjosh
Copy link

imjosh commented Jan 13, 2022

I have read and understood the contribution guidelines.
Version 2.5.0

The document created by this code appears and behaves correctly in Chrome's built-in pdf viewer. Two text fields both containing the value 'bar' should be displayed, and updating the value in one should change the value displayed in the other. A use case for this feature is multi-page documents with fields that are duplicated on each page (e.g. name and date on medical forms).

However, Adobe Acrobat does not display textField2. The PDF should contain one field element named 'foo' with two Kids. Instead it contains two field elements both named 'foo', one with the value 'bar' and the other with no value (my understanding is that violates ISO-32000-1 section 12.7.3.2 "Field names" creating an invalid PDF):

It is possible for different field dictionaries to have the same fully qualified field name if they are descendants of a common ancestor with that name and have no partial field names (T entries) of their own. Such field dictionaries are different representations of the same underlying field; they should differ only in properties that specify their visual appearance. In particular, field dictionaries with the same fully qualified field name shall have the same field type (FT), value (V), and default value (DV).

/* global jsPDF */
var doc = new jsPDF();
var {
  TextField,
} = jsPDF.AcroForm;

var textField = new TextField();
textField.Rect = [10, 10, 50, 10];
textField.fieldName = 'foo';
textField.value = 'bar';
doc.addField(textField);

var textField2 = new TextField();
textField2.Rect = [10, 30, 50, 10];
textField2.fieldName = 'foo';
doc.addField(textField2);

Document created by this code:
jsPdf example.pdf

Correctly working document created with Adobe Acrobat:
acrobat example.pdf

@HackbrettXXX
Copy link
Collaborator

Please provide a pull request and I'll merge it.

@imjosh
Copy link
Author

imjosh commented Feb 4, 2025

@HackbrettXXX Done!

#3821

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

Successfully merging a pull request may close this issue.

2 participants