Skip to content

Commit

Permalink
Merge pull request #542 from chinapandaman/PPF-541
Browse files Browse the repository at this point in the history
PPF-541: fix simple fill for existed templates
  • Loading branch information
chinapandaman authored Mar 28, 2024
2 parents 804efba + 02669c2 commit 68885b9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
1 change: 0 additions & 1 deletion PyPDFForm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
MK = "/MK"
CA = "/CA"
AS = "/AS"
Yes = "/Yes"
Off = "/Off"

# Field flag bits
Expand Down
7 changes: 5 additions & 2 deletions PyPDFForm/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Binary file not shown.
48 changes: 48 additions & 0 deletions tests/scenario/test_existed_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 68885b9

Please sign in to comment.