PyPDFForm 1.5.1__py3-none-any.whl → 1.5.3__py3-none-any.whl
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/__init__.py +1 -1
- PyPDFForm/adapter.py +1 -1
- PyPDFForm/constants.py +3 -3
- PyPDFForm/coordinate.py +15 -0
- PyPDFForm/filler.py +5 -2
- PyPDFForm/image.py +13 -1
- PyPDFForm/middleware/image.py +13 -0
- PyPDFForm/middleware/signature.py +2 -0
- PyPDFForm/wrapper.py +23 -12
- {PyPDFForm-1.5.1.dist-info → PyPDFForm-1.5.3.dist-info}/METADATA +1 -1
- {PyPDFForm-1.5.1.dist-info → PyPDFForm-1.5.3.dist-info}/RECORD +14 -14
- {PyPDFForm-1.5.1.dist-info → PyPDFForm-1.5.3.dist-info}/LICENSE +0 -0
- {PyPDFForm-1.5.1.dist-info → PyPDFForm-1.5.3.dist-info}/WHEEL +0 -0
- {PyPDFForm-1.5.1.dist-info → PyPDFForm-1.5.3.dist-info}/top_level.txt +0 -0
PyPDFForm/__init__.py
CHANGED
PyPDFForm/adapter.py
CHANGED
|
@@ -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
|
|
PyPDFForm/constants.py
CHANGED
|
@@ -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
|
PyPDFForm/coordinate.py
CHANGED
|
@@ -40,6 +40,9 @@ def get_draw_checkbox_radio_coordinates(
|
|
|
40
40
|
|
|
41
41
|
def get_draw_image_coordinates_resolutions(
|
|
42
42
|
widget: dict,
|
|
43
|
+
preserve_aspect_ratio: bool,
|
|
44
|
+
image_width: float,
|
|
45
|
+
image_height: float,
|
|
43
46
|
) -> Tuple[float, float, float, float]:
|
|
44
47
|
"""
|
|
45
48
|
Returns coordinates and resolutions to draw image at given a PDF form signature/image widget.
|
|
@@ -50,6 +53,18 @@ def get_draw_image_coordinates_resolutions(
|
|
|
50
53
|
width = abs(float(widget[Rect][0]) - float(widget[Rect][2]))
|
|
51
54
|
height = abs(float(widget[Rect][1]) - float(widget[Rect][3]))
|
|
52
55
|
|
|
56
|
+
if preserve_aspect_ratio:
|
|
57
|
+
ratio = max(image_width / width, image_height / height)
|
|
58
|
+
|
|
59
|
+
new_width = image_width / ratio
|
|
60
|
+
new_height = image_height / ratio
|
|
61
|
+
|
|
62
|
+
x += abs(new_width - width) / 2
|
|
63
|
+
y += abs(new_height - height) / 2
|
|
64
|
+
|
|
65
|
+
width = new_width
|
|
66
|
+
height = new_height
|
|
67
|
+
|
|
53
68
|
return x, y, width, height
|
|
54
69
|
|
|
55
70
|
|
PyPDFForm/filler.py
CHANGED
|
@@ -13,7 +13,7 @@ from .coordinate import (get_draw_checkbox_radio_coordinates,
|
|
|
13
13
|
get_draw_text_coordinates,
|
|
14
14
|
get_text_line_x_coordinates)
|
|
15
15
|
from .font import checkbox_radio_font_size
|
|
16
|
-
from .image import any_image_to_jpg
|
|
16
|
+
from .image import any_image_to_jpg, get_image_dimensions
|
|
17
17
|
from .middleware.checkbox import Checkbox
|
|
18
18
|
from .middleware.dropdown import Dropdown
|
|
19
19
|
from .middleware.image import Image
|
|
@@ -62,7 +62,10 @@ def signature_image_handler(
|
|
|
62
62
|
if stream is not None:
|
|
63
63
|
any_image_to_draw = True
|
|
64
64
|
stream = any_image_to_jpg(stream)
|
|
65
|
-
|
|
65
|
+
image_width, image_height = get_image_dimensions(stream)
|
|
66
|
+
x, y, width, height = get_draw_image_coordinates_resolutions(
|
|
67
|
+
widget, middleware.preserve_aspect_ratio, image_width, image_height
|
|
68
|
+
)
|
|
66
69
|
images_to_draw.append(
|
|
67
70
|
[
|
|
68
71
|
stream,
|
PyPDFForm/image.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""Contains helpers for image."""
|
|
3
3
|
|
|
4
4
|
from io import BytesIO
|
|
5
|
-
from typing import Union
|
|
5
|
+
from typing import Tuple, Union
|
|
6
6
|
|
|
7
7
|
from PIL import Image
|
|
8
8
|
|
|
@@ -28,6 +28,18 @@ def rotate_image(image_stream: bytes, rotation: Union[float, int]) -> bytes:
|
|
|
28
28
|
return result
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def get_image_dimensions(image_stream: bytes) -> Tuple[float, float]:
|
|
32
|
+
"""Gets the width and height of an image."""
|
|
33
|
+
|
|
34
|
+
buff = BytesIO()
|
|
35
|
+
buff.write(image_stream)
|
|
36
|
+
buff.seek(0)
|
|
37
|
+
|
|
38
|
+
image = Image.open(buff)
|
|
39
|
+
|
|
40
|
+
return image.size
|
|
41
|
+
|
|
42
|
+
|
|
31
43
|
def any_image_to_jpg(image_stream: bytes) -> bytes:
|
|
32
44
|
"""Converts an image of any type to jpg."""
|
|
33
45
|
|
PyPDFForm/middleware/image.py
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""Contains image field middleware."""
|
|
3
3
|
|
|
4
|
+
from typing import BinaryIO, Union
|
|
5
|
+
|
|
4
6
|
from .signature import Signature
|
|
5
7
|
|
|
6
8
|
|
|
7
9
|
class Image(Signature):
|
|
8
10
|
"""A class to represent an image field widget."""
|
|
11
|
+
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
name: str,
|
|
15
|
+
value: Union[bytes, str, BinaryIO] = None,
|
|
16
|
+
) -> None:
|
|
17
|
+
"""Constructs all attributes for the image field."""
|
|
18
|
+
|
|
19
|
+
super().__init__(name, value)
|
|
20
|
+
|
|
21
|
+
self.preserve_aspect_ratio = False
|
PyPDFForm/wrapper.py
CHANGED
|
@@ -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]
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
PyPDFForm/__init__.py,sha256=
|
|
2
|
-
PyPDFForm/adapter.py,sha256=
|
|
3
|
-
PyPDFForm/constants.py,sha256=
|
|
4
|
-
PyPDFForm/coordinate.py,sha256=
|
|
5
|
-
PyPDFForm/filler.py,sha256=
|
|
1
|
+
PyPDFForm/__init__.py,sha256=GbSU_vP9pxo3lFMOfxaLUhhW6V5_26Xh7t3B3b6rEK0,178
|
|
2
|
+
PyPDFForm/adapter.py,sha256=qt0lqd7zRzaMHD2As47oiIhungO3AyWbAkxx1ZAZi9A,862
|
|
3
|
+
PyPDFForm/constants.py,sha256=xj9CSq7PlCpAowKAlK0o8YPgPkBkJjRDToI8aiqC_c0,1749
|
|
4
|
+
PyPDFForm/coordinate.py,sha256=uZGGFiTUIrD9VX-bzgUpKlFAzK7VJppW1corGXvT-pY,7712
|
|
5
|
+
PyPDFForm/filler.py,sha256=wPVd6lwCPyZ8qPIKK1rLlKFLEWWPcYNPjuXqpC04Cws,7657
|
|
6
6
|
PyPDFForm/font.py,sha256=TbFLY4G72d7cQ3VG2g4HaYKROzQPQUmh6-8ynN6hzXY,5713
|
|
7
|
-
PyPDFForm/image.py,sha256=
|
|
7
|
+
PyPDFForm/image.py,sha256=SflPlzoTFZro2Fvd7u7bF-1mmg7D0e8YjePbQXW8YyY,1429
|
|
8
8
|
PyPDFForm/patterns.py,sha256=Z548TjpQpaVepctvlRYe0-2i7Aws96fo-ncG82CUX14,5423
|
|
9
9
|
PyPDFForm/template.py,sha256=LlnZTNF5UPLkiGqnSgHNcVr_Af6vJyg6vBf7jVD5wAM,15470
|
|
10
10
|
PyPDFForm/utils.py,sha256=9omR-oT3OdZqioxpiGqA9_P0GSFC6mg4Y1xrLvWOzkk,4309
|
|
11
11
|
PyPDFForm/watermark.py,sha256=L4LfzjjyJ6TDq9ad2dbtQYheBOic1_oZ7smhFFekNog,4725
|
|
12
|
-
PyPDFForm/wrapper.py,sha256=
|
|
12
|
+
PyPDFForm/wrapper.py,sha256=dxcFnkMv7zwT75BWZxgbrpl-Ty1dB98gjiP6xp9ihAU,11565
|
|
13
13
|
PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
PyPDFForm/middleware/base.py,sha256=Sjo8O9RrdBu73r4BCMPuLXnrl1hzjb1dlTOPeIgrhOU,1150
|
|
15
15
|
PyPDFForm/middleware/checkbox.py,sha256=0EWFECXYdz9SNxgGe1QCcRrdxLVUIJpzRYwKfGRA9e4,1346
|
|
16
16
|
PyPDFForm/middleware/dropdown.py,sha256=_RXs9o3vWH_a402zhTOYE_mcWbtFfVU7bReYcEFAIyk,793
|
|
17
|
-
PyPDFForm/middleware/image.py,sha256=
|
|
17
|
+
PyPDFForm/middleware/image.py,sha256=zR31u3dPVwhxECMGb6KaHFQrTKtbF5djBDmoyPl3WK0,475
|
|
18
18
|
PyPDFForm/middleware/radio.py,sha256=uffpK15U1gUn7mkyOcMwZByZo-I2cMWWsW3sBb1WeYk,801
|
|
19
|
-
PyPDFForm/middleware/signature.py,sha256=
|
|
19
|
+
PyPDFForm/middleware/signature.py,sha256=cDsJX7q-KSZi9Sd90Gx1c9cMyTqZBExZ-enWJMjFZNw,1147
|
|
20
20
|
PyPDFForm/middleware/text.py,sha256=7HFHy_lfBFfYbSUzgVKovSoShbNP6L7tiILIw-9_kpo,1549
|
|
21
21
|
PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
PyPDFForm/widgets/base.py,sha256=nb6HEfRdWSjZc_Th1XI62PIlgREn_JiApGC-epb6jAg,3348
|
|
23
23
|
PyPDFForm/widgets/checkbox.py,sha256=MGB6NGI-XMBz4j2erykgYOCd1pswvthuQ6UFowQOd4o,503
|
|
24
24
|
PyPDFForm/widgets/dropdown.py,sha256=2_R5xcLUWAL0G4raVgWWtE7TJdiWJITay-Gtl8YI2QI,705
|
|
25
25
|
PyPDFForm/widgets/text.py,sha256=sCB8CQAjh30QOGr8FTIDSk3X6dXSHJztOz6YkKEBDss,691
|
|
26
|
-
PyPDFForm-1.5.
|
|
27
|
-
PyPDFForm-1.5.
|
|
28
|
-
PyPDFForm-1.5.
|
|
29
|
-
PyPDFForm-1.5.
|
|
30
|
-
PyPDFForm-1.5.
|
|
26
|
+
PyPDFForm-1.5.3.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
|
|
27
|
+
PyPDFForm-1.5.3.dist-info/METADATA,sha256=GwIvR6NToB1-7l6XqlvxGct0x0gOhOrwjLL7Jg9ZAgg,4376
|
|
28
|
+
PyPDFForm-1.5.3.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
29
|
+
PyPDFForm-1.5.3.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
|
|
30
|
+
PyPDFForm-1.5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|