PyPDFForm 1.4.30__py3-none-any.whl → 1.4.31__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 +3 -1
- PyPDFForm/adapter.py +3 -4
- PyPDFForm/font.py +2 -2
- PyPDFForm/middleware/base.py +1 -0
- PyPDFForm/middleware/checkbox.py +1 -1
- PyPDFForm/middleware/dropdown.py +1 -1
- PyPDFForm/middleware/text.py +1 -1
- PyPDFForm/template.py +6 -6
- PyPDFForm/utils.py +8 -8
- PyPDFForm/watermark.py +5 -8
- PyPDFForm/widgets/base.py +5 -5
- PyPDFForm/wrapper.py +2 -3
- {PyPDFForm-1.4.30.dist-info → PyPDFForm-1.4.31.dist-info}/METADATA +1 -1
- PyPDFForm-1.4.31.dist-info/RECORD +30 -0
- {PyPDFForm-1.4.30.dist-info → PyPDFForm-1.4.31.dist-info}/WHEEL +1 -1
- PyPDFForm-1.4.30.dist-info/RECORD +0 -30
- {PyPDFForm-1.4.30.dist-info → PyPDFForm-1.4.31.dist-info}/LICENSE +0 -0
- {PyPDFForm-1.4.30.dist-info → PyPDFForm-1.4.31.dist-info}/top_level.txt +0 -0
PyPDFForm/__init__.py
CHANGED
PyPDFForm/adapter.py
CHANGED
|
@@ -13,10 +13,10 @@ def readable(obj: Any) -> bool:
|
|
|
13
13
|
|
|
14
14
|
def fp_or_f_obj_or_stream_to_stream(
|
|
15
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
|
|
|
19
|
-
result =
|
|
19
|
+
result = b""
|
|
20
20
|
if isinstance(fp_or_f_obj_or_stream, bytes):
|
|
21
21
|
result = fp_or_f_obj_or_stream
|
|
22
22
|
|
|
@@ -25,8 +25,7 @@ def fp_or_f_obj_or_stream_to_stream(
|
|
|
25
25
|
|
|
26
26
|
elif isinstance(fp_or_f_obj_or_stream, str):
|
|
27
27
|
if not isfile(fp_or_f_obj_or_stream):
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
pass
|
|
30
29
|
else:
|
|
31
30
|
with open(fp_or_f_obj_or_stream, "rb+") as _file:
|
|
32
31
|
result = _file.read()
|
PyPDFForm/font.py
CHANGED
|
@@ -42,9 +42,9 @@ def extract_font_from_text_appearance(text_appearance: str) -> Union[str, None]:
|
|
|
42
42
|
appearance string of a text field widget.
|
|
43
43
|
"""
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
text_appearances = text_appearance.split(" ")
|
|
46
46
|
|
|
47
|
-
for each in
|
|
47
|
+
for each in text_appearances:
|
|
48
48
|
if each.startswith("/"):
|
|
49
49
|
text_segments = findall("[A-Z][^A-Z]*", each.replace("/", ""))
|
|
50
50
|
|
PyPDFForm/middleware/base.py
CHANGED
PyPDFForm/middleware/checkbox.py
CHANGED
PyPDFForm/middleware/dropdown.py
CHANGED
PyPDFForm/middleware/text.py
CHANGED
PyPDFForm/template.py
CHANGED
|
@@ -118,7 +118,7 @@ def update_text_field_attributes(
|
|
|
118
118
|
) -> None:
|
|
119
119
|
"""Auto updates text fields' attributes."""
|
|
120
120
|
|
|
121
|
-
for
|
|
121
|
+
for _widgets in get_widgets_by_page(template_stream).values():
|
|
122
122
|
for _widget in _widgets:
|
|
123
123
|
key = get_widget_key(_widget)
|
|
124
124
|
|
|
@@ -155,11 +155,11 @@ def update_text_field_attributes(
|
|
|
155
155
|
def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
|
|
156
156
|
"""Iterates through a PDF and returns all widgets found grouped by page."""
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
159
159
|
|
|
160
160
|
result = {}
|
|
161
161
|
|
|
162
|
-
for i, page in enumerate(
|
|
162
|
+
for i, page in enumerate(pdf_file.pages):
|
|
163
163
|
widgets = page.annotations
|
|
164
164
|
result[i + 1] = []
|
|
165
165
|
if widgets:
|
|
@@ -177,7 +177,7 @@ def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
|
|
|
177
177
|
return result
|
|
178
178
|
|
|
179
179
|
|
|
180
|
-
def get_widget_key(widget: dict) -> Union[str, None]:
|
|
180
|
+
def get_widget_key(widget: dict) -> Union[str, list, None]:
|
|
181
181
|
"""Finds a PDF widget's annotated key by pattern matching."""
|
|
182
182
|
|
|
183
183
|
result = None
|
|
@@ -189,7 +189,7 @@ def get_widget_key(widget: dict) -> Union[str, None]:
|
|
|
189
189
|
return result
|
|
190
190
|
|
|
191
191
|
|
|
192
|
-
def get_widget_alignment(widget: dict) -> Union[str, None]:
|
|
192
|
+
def get_widget_alignment(widget: dict) -> Union[str, list, None]:
|
|
193
193
|
"""Finds a PDF widget's alignment by pattern matching."""
|
|
194
194
|
|
|
195
195
|
result = None
|
|
@@ -249,7 +249,7 @@ def is_text_multiline(widget: dict) -> bool:
|
|
|
249
249
|
return check_field_flag_bit(widget, MULTILINE)
|
|
250
250
|
|
|
251
251
|
|
|
252
|
-
def get_dropdown_choices(widget: dict) -> Union[Tuple[str], None]:
|
|
252
|
+
def get_dropdown_choices(widget: dict) -> Union[Tuple[str, ...], None]:
|
|
253
253
|
"""Returns string options of a dropdown field."""
|
|
254
254
|
|
|
255
255
|
result = None
|
PyPDFForm/utils.py
CHANGED
|
@@ -62,10 +62,10 @@ def preview_widget_to_draw(widget: WIDGET_TYPES) -> Text:
|
|
|
62
62
|
def remove_all_widgets(pdf: bytes) -> bytes:
|
|
63
63
|
"""Removes all widgets from a PDF form."""
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
66
66
|
result_stream = BytesIO()
|
|
67
67
|
writer = PdfWriter()
|
|
68
|
-
for page in
|
|
68
|
+
for page in pdf_file.pages:
|
|
69
69
|
if page.annotations:
|
|
70
70
|
page.annotations.clear()
|
|
71
71
|
writer.add_page(page)
|
|
@@ -78,10 +78,10 @@ def remove_all_widgets(pdf: bytes) -> bytes:
|
|
|
78
78
|
def get_page_streams(pdf: bytes) -> List[bytes]:
|
|
79
79
|
"""Returns a list of streams where each is a page of the input PDF."""
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
82
82
|
result = []
|
|
83
83
|
|
|
84
|
-
for page in
|
|
84
|
+
for page in pdf_file.pages:
|
|
85
85
|
writer = PdfWriter()
|
|
86
86
|
writer.add_page(page)
|
|
87
87
|
with BytesIO() as f:
|
|
@@ -96,13 +96,13 @@ def merge_two_pdfs(pdf: bytes, other: bytes) -> bytes:
|
|
|
96
96
|
"""Merges two PDFs into one PDF."""
|
|
97
97
|
|
|
98
98
|
output = PdfWriter()
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
100
|
+
other_file = PdfReader(stream_to_io(other))
|
|
101
101
|
result = BytesIO()
|
|
102
102
|
|
|
103
|
-
for page in
|
|
103
|
+
for page in pdf_file.pages:
|
|
104
104
|
output.add_page(page)
|
|
105
|
-
for page in
|
|
105
|
+
for page in other_file.pages:
|
|
106
106
|
output.add_page(page)
|
|
107
107
|
|
|
108
108
|
output.write(result)
|
PyPDFForm/watermark.py
CHANGED
|
@@ -165,12 +165,9 @@ def create_watermarks_and_draw(
|
|
|
165
165
|
watermark = buff.read()
|
|
166
166
|
buff.close()
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
results.append(watermark if i == page_number - 1 else b"")
|
|
172
|
-
|
|
173
|
-
return results
|
|
168
|
+
return [
|
|
169
|
+
watermark if i == page_number - 1 else b"" for i in range(len(pdf_file.pages))
|
|
170
|
+
]
|
|
174
171
|
|
|
175
172
|
|
|
176
173
|
def merge_watermarks_with_pdf(
|
|
@@ -180,10 +177,10 @@ def merge_watermarks_with_pdf(
|
|
|
180
177
|
"""Merges watermarks with PDF."""
|
|
181
178
|
|
|
182
179
|
result = BytesIO()
|
|
183
|
-
|
|
180
|
+
pdf_file = PdfReader(stream_to_io(pdf))
|
|
184
181
|
output = PdfWriter()
|
|
185
182
|
|
|
186
|
-
for i, page in enumerate(
|
|
183
|
+
for i, page in enumerate(pdf_file.pages):
|
|
187
184
|
if watermarks[i]:
|
|
188
185
|
watermark = PdfReader(stream_to_io(watermarks[i]))
|
|
189
186
|
if watermark.pages:
|
PyPDFForm/widgets/base.py
CHANGED
|
@@ -29,6 +29,7 @@ class Widget:
|
|
|
29
29
|
) -> None:
|
|
30
30
|
"""Sets acro form parameters."""
|
|
31
31
|
|
|
32
|
+
super().__init__()
|
|
32
33
|
self.page_number = page_number
|
|
33
34
|
self.acro_form_params = {
|
|
34
35
|
"name": name,
|
|
@@ -71,8 +72,7 @@ class Widget:
|
|
|
71
72
|
canvas.save()
|
|
72
73
|
watermark.seek(0)
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return result
|
|
75
|
+
return [
|
|
76
|
+
watermark.read() if i == self.page_number - 1 else b""
|
|
77
|
+
for i in range(page_count)
|
|
78
|
+
]
|
PyPDFForm/wrapper.py
CHANGED
|
@@ -36,6 +36,7 @@ class FormWrapper:
|
|
|
36
36
|
) -> None:
|
|
37
37
|
"""Constructs all attributes for the object."""
|
|
38
38
|
|
|
39
|
+
super().__init__()
|
|
39
40
|
self.stream = fp_or_f_obj_or_stream_to_stream(template)
|
|
40
41
|
|
|
41
42
|
def read(self) -> bytes:
|
|
@@ -292,15 +293,13 @@ class PdfWrapper(FormWrapper):
|
|
|
292
293
|
def schema(self) -> dict:
|
|
293
294
|
"""Generates a json schema for the PDF form template."""
|
|
294
295
|
|
|
295
|
-
|
|
296
|
+
return {
|
|
296
297
|
"type": "object",
|
|
297
298
|
"properties": {
|
|
298
299
|
key: value.schema_definition for key, value in self.widgets.items()
|
|
299
300
|
},
|
|
300
301
|
}
|
|
301
302
|
|
|
302
|
-
return result
|
|
303
|
-
|
|
304
303
|
@classmethod
|
|
305
304
|
def register_font(
|
|
306
305
|
cls, font_name: str, ttf_file: Union[bytes, str, BinaryIO]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
PyPDFForm/__init__.py,sha256=pRovsD1TN9FVIkHD1qURZWnJ9SMefn8yY8jivZI5Tzs,179
|
|
2
|
+
PyPDFForm/adapter.py,sha256=WFP-r8FLeKa-D9mFO9AphOcuXgyeAI1Ak0d-YsqxsK4,861
|
|
3
|
+
PyPDFForm/constants.py,sha256=FMsdOvnYpchEfki3gf_Y2Wj1SThUxMzsPbOx12_S1GA,1738
|
|
4
|
+
PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
|
|
5
|
+
PyPDFForm/filler.py,sha256=pgMA7EC8axKUganmbk7X1uDdsb4OQQFoiI85td3pOO4,7486
|
|
6
|
+
PyPDFForm/font.py,sha256=TbFLY4G72d7cQ3VG2g4HaYKROzQPQUmh6-8ynN6hzXY,5713
|
|
7
|
+
PyPDFForm/image.py,sha256=0GV8PFgY5oLJFHmhPD1fG-_5SBEO7jVLLtxCc_Uodfo,1143
|
|
8
|
+
PyPDFForm/patterns.py,sha256=p33mDZKxQN2h8GgVnZGXNolWPzofky1llIpstjnL3eI,4318
|
|
9
|
+
PyPDFForm/template.py,sha256=a9rDzhHHfnYFo8cDnHnRE9UriUykXvrsyFKVGq9DYd0,13166
|
|
10
|
+
PyPDFForm/utils.py,sha256=9omR-oT3OdZqioxpiGqA9_P0GSFC6mg4Y1xrLvWOzkk,4309
|
|
11
|
+
PyPDFForm/watermark.py,sha256=L4LfzjjyJ6TDq9ad2dbtQYheBOic1_oZ7smhFFekNog,4725
|
|
12
|
+
PyPDFForm/wrapper.py,sha256=Rrb7PhbAWEWOwOX3Z5m-TEfTZfCnEY4AsWg7ashPe7c,9498
|
|
13
|
+
PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
PyPDFForm/middleware/base.py,sha256=p-3XsZJ6d7ai2JFLF7LisMWi9yzM3pN7CsFECxtEoI0,751
|
|
15
|
+
PyPDFForm/middleware/checkbox.py,sha256=3-9CMhhtyO9U6lLXDciW-59ng8uS4m6_clPB02mzV9c,1317
|
|
16
|
+
PyPDFForm/middleware/dropdown.py,sha256=On4bn8U9NSzDqytLEQuP5nEGTanJUm_DjtykYcJpyrI,672
|
|
17
|
+
PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
|
|
18
|
+
PyPDFForm/middleware/radio.py,sha256=ehaJoehEzZqxDVb5A6fJkYludeBmtV2Z5GZUPPfUWng,700
|
|
19
|
+
PyPDFForm/middleware/signature.py,sha256=m7tNvGZ7fQ0yuVKzSlLbNQ2IILo1GDnjzMDzMnYCKVM,1104
|
|
20
|
+
PyPDFForm/middleware/text.py,sha256=LNY_9Y2tq3uQEneKoL4vgrJtFTva0KSYzuuzDb5METM,1055
|
|
21
|
+
PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
PyPDFForm/widgets/base.py,sha256=mb8pKLu9d80pr-175T8f0FI1kWo2IOJ5am2_zRQKUl0,2075
|
|
23
|
+
PyPDFForm/widgets/checkbox.py,sha256=MGB6NGI-XMBz4j2erykgYOCd1pswvthuQ6UFowQOd4o,503
|
|
24
|
+
PyPDFForm/widgets/dropdown.py,sha256=2_R5xcLUWAL0G4raVgWWtE7TJdiWJITay-Gtl8YI2QI,705
|
|
25
|
+
PyPDFForm/widgets/text.py,sha256=x8EglZLYoI9osN9wORLRYoR7lebrpj-wx38QiRH7H1A,629
|
|
26
|
+
PyPDFForm-1.4.31.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
|
|
27
|
+
PyPDFForm-1.4.31.dist-info/METADATA,sha256=gnvLbIDdwFs1FaYpgGx2rgjTMEA1KeFHngG72BH-CtU,4151
|
|
28
|
+
PyPDFForm-1.4.31.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
29
|
+
PyPDFForm-1.4.31.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
|
|
30
|
+
PyPDFForm-1.4.31.dist-info/RECORD,,
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
PyPDFForm/__init__.py,sha256=qhBV2ZeK4rXK6ALggenAeEKbQNeDPTqkc48DVVtCFWg,138
|
|
2
|
-
PyPDFForm/adapter.py,sha256=OgAIwcmukpBqHFBLymd3I7wA7wIdipRqgURZA2Y0Hgo,885
|
|
3
|
-
PyPDFForm/constants.py,sha256=FMsdOvnYpchEfki3gf_Y2Wj1SThUxMzsPbOx12_S1GA,1738
|
|
4
|
-
PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
|
|
5
|
-
PyPDFForm/filler.py,sha256=pgMA7EC8axKUganmbk7X1uDdsb4OQQFoiI85td3pOO4,7486
|
|
6
|
-
PyPDFForm/font.py,sha256=DCaKN6WIfNeMpP6ud17q1FOVRQXqrdevLycIQ9kItXQ,5711
|
|
7
|
-
PyPDFForm/image.py,sha256=0GV8PFgY5oLJFHmhPD1fG-_5SBEO7jVLLtxCc_Uodfo,1143
|
|
8
|
-
PyPDFForm/patterns.py,sha256=p33mDZKxQN2h8GgVnZGXNolWPzofky1llIpstjnL3eI,4318
|
|
9
|
-
PyPDFForm/template.py,sha256=u3QxYdsT8HhoUBlhmChYaTJeFWI-SSrhICtUYsTTrow,13141
|
|
10
|
-
PyPDFForm/utils.py,sha256=gDeRDszZ5Q59RjZjJYnikS2pQ_hc78osQH2Oy1TuLsY,4269
|
|
11
|
-
PyPDFForm/watermark.py,sha256=clYdRqCuWEE25IL-BUHnSo4HgLkHPSOl7FUJLhbAfGg,4755
|
|
12
|
-
PyPDFForm/wrapper.py,sha256=nwmaBkcnd0wt53s9SHHWFCvSJX4J2f7MU3ktt3105WU,9496
|
|
13
|
-
PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
PyPDFForm/middleware/base.py,sha256=TmoO8XpjFa5NerAumrAGm_kUt2eFP3DyyF-Vx0uXloM,724
|
|
15
|
-
PyPDFForm/middleware/checkbox.py,sha256=Z92awlKjceMd_ryb9Fhrtyd4fLkU84Ii6fSum60rHcA,1305
|
|
16
|
-
PyPDFForm/middleware/dropdown.py,sha256=BpRh2YPndhhaLY-s-3gqck64d5FoC719-ARgvfV3_N0,674
|
|
17
|
-
PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
|
|
18
|
-
PyPDFForm/middleware/radio.py,sha256=ehaJoehEzZqxDVb5A6fJkYludeBmtV2Z5GZUPPfUWng,700
|
|
19
|
-
PyPDFForm/middleware/signature.py,sha256=m7tNvGZ7fQ0yuVKzSlLbNQ2IILo1GDnjzMDzMnYCKVM,1104
|
|
20
|
-
PyPDFForm/middleware/text.py,sha256=-ETNQoLvgu5cLkpIQtNYHtq75Ou3P7ezYur-E1yb9-k,1057
|
|
21
|
-
PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
-
PyPDFForm/widgets/base.py,sha256=Stq-oQt-cfwQ6nilQ4NqpO5udFSKDNb1mAwryrWggZA,2076
|
|
23
|
-
PyPDFForm/widgets/checkbox.py,sha256=MGB6NGI-XMBz4j2erykgYOCd1pswvthuQ6UFowQOd4o,503
|
|
24
|
-
PyPDFForm/widgets/dropdown.py,sha256=2_R5xcLUWAL0G4raVgWWtE7TJdiWJITay-Gtl8YI2QI,705
|
|
25
|
-
PyPDFForm/widgets/text.py,sha256=x8EglZLYoI9osN9wORLRYoR7lebrpj-wx38QiRH7H1A,629
|
|
26
|
-
PyPDFForm-1.4.30.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
|
|
27
|
-
PyPDFForm-1.4.30.dist-info/METADATA,sha256=l5vS_GMEnKq-mC_2MuE0fsORqiF9QrWUKOfFuc1t-P0,4151
|
|
28
|
-
PyPDFForm-1.4.30.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
29
|
-
PyPDFForm-1.4.30.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
|
|
30
|
-
PyPDFForm-1.4.30.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|