unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.56k stars 251 forks source link

Checkboxes in an array are not being filled consistently. #466

Closed GalacticGuac closed 3 years ago

GalacticGuac commented 3 years ago

Description

Checkboxes are not being filled consistently on the IRS W9 form. The form has a section of named PDF fields that indicate they are some kind of checkbox array, but only the first box of 8 functions as intended, allowing it to be filled or not with a value of "0" or "1".

Expected Behavior

All adjacent checkboxes should be filled using the same logic.

Actual Behavior

Steps to reproduce the behavior:

  1. Download IRS W9 form from https://www.irs.gov/pub/irs-pdf/fw9.pdf
  2. Use the UniPDF functions to find the field names, and structure the data accordingly
  3. User pdfReader.AcroForm.FillWithAppearance() to fill out the data
  4. All fields will be filled, except for the checkboxes. Of which, only the first is ever able to be checked.

Attachments

Self contained reproduction code: checkbox-debug.txt

Attachment from above link: W9.pdf

github-actions[bot] commented 3 years ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/

gunnsth commented 3 years ago

The checkboxes check states in W9.pdf file are using indexes, i.e. "1", "2", "3", etc. You can list available states using our example in unipdf-examples/forms/pdf_form_fill_json.go. When you run that example, you should see the checkboxes listed like this:

 {
        "name": "topmostSubform[0].Page1[0].FederalClassification[0].c1_1[6]",
        "value": "Off",
        "options": [
            "7",
            "Off"
        ]
    },

For above example, one would use "7" as value of field to appear as checked.

So only the first one was working because it had options "1" and "Off", whereas the next one had "2" and "Off" etc. But the code was putting "1" for those as well. If an option does not exist, it means it will appear as not checked.