Fill form - Checkbox
See original GitHub issueHi,
First, fantastic work and effort is put in here - the docs, the code, the explanations, the comments! Very concise and user friendly. Thank you for that.
Environment is typescript in node, and pdf-lib v1.16.0.
If in my PDF I have checkboxes like this (this was forwarded by 3rd party person, not generated by me)

and with logs like this
const form = pdfDoc.getForm();
form.getFields().forEach((field) => {
  console.log('FIELD ---- ', `name: ${field.getName()}; type: ${field.constructor.name}`);
});
i have output:
FIELD ---- name: Status; type: PDFCheckBox
With command const status = form.getCheckBox('Status'); and status.check(); the only first checkbox gets checked.
The problem for me here is that I don’t know how to manipulate with particular checkboxes (‘Single or Head of household’, ‘Married’, ‘Married, but withhold at higher single rate’).
I was wondering where the problem lies:
- in the PDF implementation?
 - or am I missing something in my code?
 
Giving any kind of directions or hints would be very much appreciated. If I can provide more details from logs, please let me know. Cheers!
Issue Analytics
- State:
 - Created 3 years ago
 - Reactions:2
 - Comments:8 (3 by maintainers)
 

Top Related StackOverflow Question
OK, we managed to do it after diving into
PDFCheckBox.tsfile &setValuemethod andPDFAcroCheckBox.tsfile &setValuemethod. PDFCheckBox.ts file:PDFAcroCheckBox.ts file:
Our code for demonstration:
Now we can check all checkboxes if we want while with
status.check()we can check only first one.I have also tried w/ & w/o
.markAsDirty()method but it made no visual difference. Any suggestions or corrections are most welcomed!EDIT: another way of managing something is to edit PDF online with https://www.pdfescape.com/, delete existing checkboxes and insert your own checkbox form fields. In that way you should have desired behavior with
.check().I took a similar approach when
field.check()check didn’t work for me. Same scenario where multiple checkboxes for a given field and I want to be able to set one of themIt provided the ability to set an individual check box for a field however I am still facing issues with this, as once I call
field.enableReadOnly()It changes the appearance of the checkbox from a cross to a tick.