chinapandaman / PyPDFForm

:fire: The Python library for PDF forms.
https://chinapandaman.github.io/PyPDFForm/
MIT License
438 stars 19 forks source link

Cannot parse checkbox's Description #757

Closed freaksie closed 1 week ago

freaksie commented 1 week ago

Version

PyPDFForm=1.4.37

Issue Description

Unable to parse the description for the checkbox. This is important info for someone who has no reference to the original template (PDF).

Code Snippet

import json
from PyPDFForm import PdfWrapper
pdf_form_schema = PdfWrapper("i-90.pdf").schema
print(json.dumps(pdf_form_schema, indent=4, sort_keys=True))

Sample of Json Output

{
        "P1_checkbox4[1]": {
            "type": "boolean"
        },
        "P1_checkbox4[2]": {
            "type": "boolean"
        },
        "P1_checkbox6c_Unit[0]": {
            "type": "boolean"
        },
        "P1_checkbox6c_Unit[1]": {
            "type": "boolean"
        },
        "P1_checkbox6c_Unit[2]": {
            "type": "boolean"
        }
}

PDF Form Template

i-90.pdf

Screenshots (if applicable)

image

freaksie commented 1 week ago

I tried to extract the TU ('/TU'), but its not working

WIDGET_KEY_PATTERNS = [
    {T: True},
    {TU: True},
    {Parent: {T: True, TU: True}},
]

I see the description is present in widget instance

'/T': 'P1_Line3c_MiddleName[0]', '/TU': 'Part 1. Information About You. Your Full Name. 3. C. Enter Middle Name.'

freaksie commented 1 week ago

Solved

Had to modify some files Created new function in template.py get_widget_description

        P1_checkbox4[0]": {
            "description": "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select Yes. (Proceed to Item Numbers 5. A. through 5. C.).",
            "type": "boolean"
        },
        "P1_checkbox4[1]": {
            "description": "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select No (Proceed to Item Numbers 6. A. through 6. I.).",
            "type": "boolean"
        },
        "P1_checkbox4[2]": {
            "description": "Part 1. Information About You. Your Full Name. 4. Has your name legally changed since the issuance of your Permanent Resident Card? Select Not Applicable - I never received my previous card. (Proceed to Item Numbers 6. A. through 6. I.).",
            "type": "boolean"
        },

Let me know if you want me to push the changes @chinapandaman

chinapandaman commented 5 days ago

Hey thanks for posting, and sorry for a rather late response.

You can open a PR against branch PPF-757 if you want.