PyPDFForm 1.5.1__tar.gz → 1.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of PyPDFForm might be problematic. Click here for more details.
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PKG-INFO +1 -1
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/__init__.py +1 -1
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/adapter.py +1 -1
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/constants.py +3 -3
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/wrapper.py +23 -12
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm.egg-info/PKG-INFO +1 -1
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_functional.py +16 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/LICENSE +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/coordinate.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/filler.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/font.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/image.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/__init__.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/base.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/checkbox.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/dropdown.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/image.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/radio.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/signature.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/middleware/text.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/patterns.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/template.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/utils.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/watermark.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/widgets/__init__.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/widgets/base.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/widgets/checkbox.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/widgets/dropdown.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm/widgets/text.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm.egg-info/SOURCES.txt +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm.egg-info/dependency_links.txt +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm.egg-info/requires.txt +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/PyPDFForm.egg-info/top_level.txt +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/README.md +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/setup.cfg +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/setup.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_adobe_mode.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_create_widget.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_dropdown.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_dropdown_simple.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_fill_max_length_text_field.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_fill_max_length_text_field_simple.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_fill_method.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_functional_simple.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_paragraph.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_paragraph_simple.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_preview.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_signature.py +0 -0
- {pypdfform-1.5.1 → pypdfform-1.5.2}/tests/test_use_full_widget_name.py +0 -0
|
@@ -12,7 +12,7 @@ def readable(obj: Any) -> bool:
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def fp_or_f_obj_or_stream_to_stream(
|
|
15
|
-
fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO]
|
|
15
|
+
fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO],
|
|
16
16
|
) -> bytes:
|
|
17
17
|
"""Converts a file path or a file object to a stream."""
|
|
18
18
|
|
|
@@ -76,11 +76,11 @@ NEW_LINE_SYMBOL = "\n"
|
|
|
76
76
|
IMAGE_FIELD_IDENTIFIER = "event.target.buttonImportIcon();"
|
|
77
77
|
|
|
78
78
|
DEFAULT_CHECKBOX_STYLE = "\u2713"
|
|
79
|
-
DEFAULT_RADIO_STYLE = "\
|
|
79
|
+
DEFAULT_RADIO_STYLE = "\u25cf"
|
|
80
80
|
BUTTON_STYLES = {
|
|
81
81
|
"4": "\u2713", # check
|
|
82
|
-
"5": "\
|
|
83
|
-
"l": "\
|
|
82
|
+
"5": "\u00d7", # cross
|
|
83
|
+
"l": "\u25cf", # circle
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO = DEFAULT_FONT_SIZE / 100
|
|
@@ -71,6 +71,13 @@ class FormWrapper:
|
|
|
71
71
|
class PdfWrapper(FormWrapper):
|
|
72
72
|
"""A class to represent a PDF form."""
|
|
73
73
|
|
|
74
|
+
USER_PARAMS = [
|
|
75
|
+
"global_font",
|
|
76
|
+
"global_font_size",
|
|
77
|
+
"global_font_color",
|
|
78
|
+
"use_full_widget_name",
|
|
79
|
+
]
|
|
80
|
+
|
|
74
81
|
def __init__(
|
|
75
82
|
self,
|
|
76
83
|
template: Union[bytes, str, BinaryIO] = b"",
|
|
@@ -82,11 +89,8 @@ class PdfWrapper(FormWrapper):
|
|
|
82
89
|
self.widgets = {}
|
|
83
90
|
self._keys_to_update = []
|
|
84
91
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
self.global_font_color = kwargs.get("global_font_color")
|
|
88
|
-
|
|
89
|
-
self.use_full_widget_name = kwargs.get("use_full_widget_name", False)
|
|
92
|
+
for each in self.USER_PARAMS:
|
|
93
|
+
setattr(self, each, kwargs.get(each))
|
|
90
94
|
|
|
91
95
|
self._init_helper()
|
|
92
96
|
|
|
@@ -95,7 +99,9 @@ class PdfWrapper(FormWrapper):
|
|
|
95
99
|
|
|
96
100
|
refresh_not_needed = {}
|
|
97
101
|
new_widgets = (
|
|
98
|
-
build_widgets(self.read(), self
|
|
102
|
+
build_widgets(self.read(), getattr(self, "use_full_widget_name"))
|
|
103
|
+
if self.read()
|
|
104
|
+
else {}
|
|
99
105
|
)
|
|
100
106
|
for k, v in self.widgets.items():
|
|
101
107
|
if k in new_widgets:
|
|
@@ -109,9 +115,9 @@ class PdfWrapper(FormWrapper):
|
|
|
109
115
|
and isinstance(value, Text)
|
|
110
116
|
and not refresh_not_needed.get(key)
|
|
111
117
|
):
|
|
112
|
-
value.font = self
|
|
113
|
-
value.font_size = self
|
|
114
|
-
value.font_color = self
|
|
118
|
+
value.font = getattr(self, "global_font")
|
|
119
|
+
value.font_size = getattr(self, "global_font_size")
|
|
120
|
+
value.font_color = getattr(self, "global_font_color")
|
|
115
121
|
|
|
116
122
|
@property
|
|
117
123
|
def sample_data(self) -> dict:
|
|
@@ -133,7 +139,12 @@ class PdfWrapper(FormWrapper):
|
|
|
133
139
|
def pages(self) -> List[PdfWrapper]:
|
|
134
140
|
"""Returns a list of pdf wrapper objects where each is a page of the PDF form."""
|
|
135
141
|
|
|
136
|
-
return [
|
|
142
|
+
return [
|
|
143
|
+
self.__class__(
|
|
144
|
+
each, **{param: getattr(self, param) for param in self.USER_PARAMS}
|
|
145
|
+
)
|
|
146
|
+
for each in get_page_streams(self.stream)
|
|
147
|
+
]
|
|
137
148
|
|
|
138
149
|
def change_version(self, version: str) -> PdfWrapper:
|
|
139
150
|
"""Changes the version of the PDF."""
|
|
@@ -258,7 +269,7 @@ class PdfWrapper(FormWrapper):
|
|
|
258
269
|
) -> PdfWrapper:
|
|
259
270
|
"""Updates the key of an existed widget on a PDF form."""
|
|
260
271
|
|
|
261
|
-
if self
|
|
272
|
+
if getattr(self, "use_full_widget_name"):
|
|
262
273
|
raise NotImplementedError
|
|
263
274
|
|
|
264
275
|
if defer:
|
|
@@ -275,7 +286,7 @@ class PdfWrapper(FormWrapper):
|
|
|
275
286
|
def commit_widget_key_updates(self) -> PdfWrapper:
|
|
276
287
|
"""Commits all deferred widget key updates on a PDF form."""
|
|
277
288
|
|
|
278
|
-
if self
|
|
289
|
+
if getattr(self, "use_full_widget_name"):
|
|
279
290
|
raise NotImplementedError
|
|
280
291
|
|
|
281
292
|
old_keys = [each[0] for each in self._keys_to_update]
|
|
@@ -516,6 +516,22 @@ def test_pages(template_stream, pdf_samples, request):
|
|
|
516
516
|
assert obj.pages[0].read() == f.read()
|
|
517
517
|
|
|
518
518
|
|
|
519
|
+
def test_pages_inherit_attributes(template_stream):
|
|
520
|
+
obj = PdfWrapper(
|
|
521
|
+
template_stream,
|
|
522
|
+
global_font="Courier",
|
|
523
|
+
global_font_size=20,
|
|
524
|
+
global_font_color=(1, 0, 0),
|
|
525
|
+
use_full_widget_name=True,
|
|
526
|
+
)
|
|
527
|
+
|
|
528
|
+
for page in obj.pages:
|
|
529
|
+
assert getattr(page, "global_font") == "Courier"
|
|
530
|
+
assert getattr(page, "global_font_size") == 20
|
|
531
|
+
assert getattr(page, "global_font_color") == (1, 0, 0)
|
|
532
|
+
assert getattr(page, "use_full_widget_name")
|
|
533
|
+
|
|
534
|
+
|
|
519
535
|
def test_generate_coordinate_grid(template_stream, pdf_samples, request):
|
|
520
536
|
expected_path = os.path.join(pdf_samples, "test_generate_coordinate_grid.pdf")
|
|
521
537
|
with open(expected_path, "rb+") as f:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|