diff --git a/PyPDFForm/constants.py b/PyPDFForm/constants.py index 1adfc6f2..1b39dd25 100644 --- a/PyPDFForm/constants.py +++ b/PyPDFForm/constants.py @@ -48,7 +48,6 @@ MK = "/MK" CA = "/CA" AS = "/AS" -Yes = "/Yes" Off = "/Off" # Field flag bits diff --git a/PyPDFForm/patterns.py b/PyPDFForm/patterns.py index 6e3e53c0..b2681bbe 100644 --- a/PyPDFForm/patterns.py +++ b/PyPDFForm/patterns.py @@ -5,7 +5,7 @@ TextStringObject) from .constants import (AP, AS, CA, DA, FT, MK, READ_ONLY, Btn, Ch, D, Ff, Off, - Opt, Parent, Q, Sig, Subtype, T, Tx, V, Widget, Yes) + Opt, Parent, Q, Sig, Subtype, T, Tx, V, Widget) from .middleware.checkbox import Checkbox from .middleware.dropdown import Dropdown from .middleware.radio import Radio @@ -83,7 +83,10 @@ def simple_update_checkbox_value(annot: DictionaryObject) -> None: """Patterns to update values for checkbox annotations.""" - annot[NameObject(AS)] = NameObject(Yes) + for each in annot[AP][D]: # noqa + if str(each) != Off: + annot[NameObject(AS)] = NameObject(each) + break def simple_update_radio_value(annot: DictionaryObject) -> None: diff --git a/pdf_samples/simple/scenario/existed/illinois-gun-bill-of-sale_expected.pdf b/pdf_samples/simple/scenario/existed/illinois-gun-bill-of-sale_expected.pdf new file mode 100644 index 00000000..e96bc1c2 Binary files /dev/null and b/pdf_samples/simple/scenario/existed/illinois-gun-bill-of-sale_expected.pdf differ diff --git a/tests/scenario/test_existed_simple.py b/tests/scenario/test_existed_simple.py index fedd5507..79d9df54 100644 --- a/tests/scenario/test_existed_simple.py +++ b/tests/scenario/test_existed_simple.py @@ -5,6 +5,54 @@ from PyPDFForm import FormWrapper +def test_illinois_gun_bill_of_sale(existed_pdf_directory, pdf_samples, request): + expected_path = os.path.join( + pdf_samples, "simple", "scenario", "existed", "illinois-gun-bill-of-sale_expected.pdf" + ) + with open(expected_path, "rb+") as f: + obj = FormWrapper(os.path.join(existed_pdf_directory, "illinois-gun-bill-of-sale.pdf")).fill( + { + "Date": "01-01", + "20": "22", + "Buyers Name": "John Doe", + "undefined": "1 N Main St, Chicago, IL 60000", + "Sellers Name": "Jack Smith", + "undefined_2": "2 S Main St, Chicago, IL 60000", + "Make": "AK", + "TypeModel": "47", + "Caliber": "7.62-x39mm", + "Serial Number SN": "111111", + "Seller accepts cash payment in the amount of": True, + "The date of this bill of sale": True, + "At a future date no later than": True, + "Other": True, + "undefined_4": "NO REASONS", + "to": "400", + "undefined_3": "01-01", + "20_2": "23", + "undefined_5": "Food", + "Buyer is receiving the Firearm as a Gift": True, + "Seller accepts trade for the Firearm in exchange for": True, + "Print Name": "John Doe", + "Print Name_2": "Jack Smith", + "Date_2": "2021-01-01", + "Date_3": "2021-01-01", + "Drivers License Number": "D000-4609-0001", + "Drivers License Number_2": "S530-4209-0001", + "State": "IL", + "State_2": "IL", + } + ) + + request.config.results["expected_path"] = expected_path + request.config.results["stream"] = obj.read() + + expected = f.read() + + assert len(obj.read()) == len(expected) + assert obj.stream == expected + + def test_ds82(existed_pdf_directory, pdf_samples, request): expected_path = os.path.join( pdf_samples, "simple", "scenario", "existed", "DS82_expected.pdf"