Skip to content

Commit 29c7fbb

Browse files
Merge pull request #617 from chinapandaman/PPF-614
PPF-614: refine the pattern that determines a checkbox
2 parents dbe6de9 + 635ca69 commit 29c7fbb

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

PyPDFForm/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
MK = "/MK"
5252
CA = "/CA"
5353
AS = "/AS"
54+
Yes = "/Yes"
5455
Off = "/Off"
5556

5657
# Field flag bits

PyPDFForm/patterns.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from .constants import (AP, AS, CA, DA, FT, IMAGE_FIELD_IDENTIFIER, JS, MK,
88
READ_ONLY, A, Btn, Ch, D, Ff, Off, Opt, Parent, Q, Sig,
9-
Subtype, T, Tx, V, Widget)
9+
Subtype, T, Tx, V, Widget, Yes)
1010
from .middleware.checkbox import Checkbox
1111
from .middleware.dropdown import Dropdown
1212
from .middleware.image import Image
@@ -28,7 +28,10 @@
2828
Text,
2929
),
3030
(
31-
({FT: Btn},),
31+
(
32+
{FT: Btn},
33+
{AS: (Yes, Off)},
34+
),
3235
Checkbox,
3336
),
3437
(
@@ -47,11 +50,15 @@
4750
(
4851
{Parent: {FT: Btn}},
4952
{Parent: {Subtype: Widget}},
53+
{AS: (Yes, Off)},
5054
),
5155
Checkbox,
5256
),
5357
(
54-
({Parent: {FT: Btn}},),
58+
(
59+
{Parent: {FT: Btn}},
60+
{AS: (Yes, Off)},
61+
),
5562
Radio,
5663
),
5764
]

PyPDFForm/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ def find_pattern_match(pattern: dict, widget: Union[dict, DictionaryObject]) ->
122122
):
123123
result = find_pattern_match(pattern[key], value)
124124
else:
125-
result = pattern[key] == value
125+
if isinstance(pattern[key], tuple):
126+
result = value in pattern[key]
127+
else:
128+
result = pattern[key] == value
126129
if result:
127130
return result
128131
return False
1.8 MB
Binary file not shown.

tests/scenario/test_existed.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,11 @@ def test_illinois_real_estate_power_of_attorney_form(existed_pdf_directory, requ
184184
expected = f.read()
185185
assert len(obj.read()) == len(expected)
186186
assert obj.read() == expected
187+
188+
189+
def test_clear_form_button_not_checkbox(existed_pdf_directory):
190+
obj = PdfWrapper(
191+
os.path.join(existed_pdf_directory, "ds11_pdf.pdf")
192+
)
193+
194+
assert "Clear" not in obj.widgets

0 commit comments

Comments
 (0)