PyPDFForm 3.5.0__py3-none-any.whl → 3.5.2__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/hooks.py +15 -3
- PyPDFForm/patterns.py +29 -2
- PyPDFForm/template.py +10 -5
- {pypdfform-3.5.0.dist-info → pypdfform-3.5.2.dist-info}/METADATA +1 -1
- {pypdfform-3.5.0.dist-info → pypdfform-3.5.2.dist-info}/RECORD +9 -9
- {pypdfform-3.5.0.dist-info → pypdfform-3.5.2.dist-info}/WHEEL +0 -0
- {pypdfform-3.5.0.dist-info → pypdfform-3.5.2.dist-info}/licenses/LICENSE +0 -0
- {pypdfform-3.5.0.dist-info → pypdfform-3.5.2.dist-info}/top_level.txt +0 -0
PyPDFForm/__init__.py
CHANGED
|
@@ -20,7 +20,7 @@ The library supports various PDF form features, including:
|
|
|
20
20
|
PyPDFForm aims to simplify PDF form manipulation, making it accessible to developers of all skill levels.
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
-
__version__ = "3.5.
|
|
23
|
+
__version__ = "3.5.2"
|
|
24
24
|
|
|
25
25
|
from .middleware.text import Text # exposing for setting global font attrs
|
|
26
26
|
from .widgets import Fields
|
PyPDFForm/hooks.py
CHANGED
|
@@ -83,19 +83,31 @@ def update_text_field_font(annot: DictionaryObject, val: str) -> None:
|
|
|
83
83
|
Updates the font of a text field annotation.
|
|
84
84
|
|
|
85
85
|
This function modifies the appearance string (DA) in the annotation dictionary
|
|
86
|
-
to change the font used for the text field.
|
|
86
|
+
to change the font used for the text field. It ensures that the provided font
|
|
87
|
+
name is a proper PDF font by checking if it starts with a slash "/".
|
|
88
|
+
The function then correctly identifies and updates the font in the appearance
|
|
89
|
+
stream by locating the existing font identifier (which also starts with a slash).
|
|
87
90
|
|
|
88
91
|
Args:
|
|
89
92
|
annot (DictionaryObject): The annotation dictionary for the text field.
|
|
90
|
-
val (str): The new font name to use for the text field.
|
|
93
|
+
val (str): The new font name to use for the text field. Must start with "/".
|
|
91
94
|
"""
|
|
95
|
+
if not val.startswith("/"):
|
|
96
|
+
return
|
|
92
97
|
if Parent in annot and DA not in annot:
|
|
93
98
|
text_appearance = annot[Parent][DA]
|
|
94
99
|
else:
|
|
95
100
|
text_appearance = annot[DA]
|
|
96
101
|
|
|
97
102
|
text_appearance = text_appearance.split(" ")
|
|
98
|
-
|
|
103
|
+
|
|
104
|
+
index_to_update = 0
|
|
105
|
+
for i, each in enumerate(text_appearance):
|
|
106
|
+
if each.startswith("/"):
|
|
107
|
+
index_to_update = i
|
|
108
|
+
break
|
|
109
|
+
|
|
110
|
+
text_appearance[index_to_update] = val
|
|
99
111
|
new_text_appearance = " ".join(text_appearance)
|
|
100
112
|
|
|
101
113
|
if Parent in annot and DA not in annot:
|
PyPDFForm/patterns.py
CHANGED
|
@@ -17,8 +17,9 @@ from typing import Union
|
|
|
17
17
|
from pypdf.generic import (ArrayObject, DictionaryObject, NameObject,
|
|
18
18
|
NumberObject, TextStringObject)
|
|
19
19
|
|
|
20
|
-
from .constants import (AP, AS, DV, FT, IMAGE_FIELD_IDENTIFIER, JS,
|
|
21
|
-
A, Btn, Ch, I, N, Off, Opt, Parent, Sig,
|
|
20
|
+
from .constants import (AP, AS, DV, FT, IMAGE_FIELD_IDENTIFIER, JS, MULTILINE,
|
|
21
|
+
SLASH, TU, A, Btn, Ch, Ff, I, N, Off, Opt, Parent, Sig,
|
|
22
|
+
T, Tx, V, Yes)
|
|
22
23
|
from .middleware.checkbox import Checkbox
|
|
23
24
|
from .middleware.dropdown import Dropdown
|
|
24
25
|
from .middleware.image import Image
|
|
@@ -277,3 +278,29 @@ def update_annotation_name(annot: DictionaryObject, val: str) -> None:
|
|
|
277
278
|
annot[NameObject(Parent)][NameObject(T)] = TextStringObject(val)
|
|
278
279
|
else:
|
|
279
280
|
annot[NameObject(T)] = TextStringObject(val)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def get_text_field_multiline(annot: DictionaryObject) -> bool:
|
|
284
|
+
"""
|
|
285
|
+
Checks if a text field annotation is multiline.
|
|
286
|
+
|
|
287
|
+
This function inspects the 'Ff' (field flags) entry of the text annotation
|
|
288
|
+
dictionary (or its parent if it's a child annotation) to determine if the
|
|
289
|
+
Multiline flag is set.
|
|
290
|
+
|
|
291
|
+
Args:
|
|
292
|
+
annot (DictionaryObject): The text annotation dictionary.
|
|
293
|
+
|
|
294
|
+
Returns:
|
|
295
|
+
bool: True if the text field is multiline, False otherwise.
|
|
296
|
+
"""
|
|
297
|
+
if Parent in annot and Ff not in annot:
|
|
298
|
+
return bool(
|
|
299
|
+
int(
|
|
300
|
+
annot[NameObject(Parent)][NameObject(Ff)]
|
|
301
|
+
if Ff in annot[NameObject(Parent)]
|
|
302
|
+
else 0
|
|
303
|
+
)
|
|
304
|
+
& MULTILINE
|
|
305
|
+
)
|
|
306
|
+
return bool(int(annot[NameObject(Ff)] if Ff in annot else 0) & MULTILINE)
|
PyPDFForm/template.py
CHANGED
|
@@ -28,7 +28,8 @@ from .middleware.text import Text
|
|
|
28
28
|
from .patterns import (DROPDOWN_CHOICE_PATTERNS, WIDGET_DESCRIPTION_PATTERNS,
|
|
29
29
|
WIDGET_KEY_PATTERNS, WIDGET_TYPE_PATTERNS,
|
|
30
30
|
get_checkbox_value, get_dropdown_value, get_radio_value,
|
|
31
|
-
get_text_value,
|
|
31
|
+
get_text_field_multiline, get_text_value,
|
|
32
|
+
update_annotation_name)
|
|
32
33
|
from .utils import extract_widget_property, find_pattern_match, stream_to_io
|
|
33
34
|
|
|
34
35
|
|
|
@@ -69,6 +70,7 @@ def build_widgets(
|
|
|
69
70
|
# mostly for schema for now
|
|
70
71
|
# doesn't trigger hook
|
|
71
72
|
_widget.__dict__["max_length"] = get_text_field_max_length(widget)
|
|
73
|
+
_widget.__dict__["multiline"] = get_text_field_multiline(widget)
|
|
72
74
|
get_text_value(widget, _widget)
|
|
73
75
|
|
|
74
76
|
if type(_widget) is Checkbox:
|
|
@@ -150,20 +152,23 @@ def get_widget_key(widget: dict, use_full_widget_name: bool) -> str:
|
|
|
150
152
|
Returns:
|
|
151
153
|
str: The extracted widget key.
|
|
152
154
|
"""
|
|
153
|
-
key = extract_widget_property(widget, WIDGET_KEY_PATTERNS, None, str)
|
|
154
155
|
if not use_full_widget_name:
|
|
155
|
-
return
|
|
156
|
+
return extract_widget_property(widget, WIDGET_KEY_PATTERNS, None, str)
|
|
156
157
|
|
|
158
|
+
key = widget.get(T)
|
|
157
159
|
if (
|
|
158
160
|
Parent in widget
|
|
159
161
|
and T in widget[Parent].get_object()
|
|
160
162
|
and widget[Parent].get_object()[T] != key # sejda case
|
|
161
163
|
):
|
|
162
|
-
key
|
|
164
|
+
if key is None:
|
|
165
|
+
return get_widget_key(widget[Parent].get_object(), use_full_widget_name)
|
|
166
|
+
|
|
167
|
+
return (
|
|
163
168
|
f"{get_widget_key(widget[Parent].get_object(), use_full_widget_name)}.{key}"
|
|
164
169
|
)
|
|
165
170
|
|
|
166
|
-
return key
|
|
171
|
+
return key or ""
|
|
167
172
|
|
|
168
173
|
|
|
169
174
|
def construct_widget(widget: dict, key: str) -> Union[WIDGET_TYPES, None]:
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
PyPDFForm/__init__.py,sha256=
|
|
1
|
+
PyPDFForm/__init__.py,sha256=g66KyIWGw_i9Ncx2rTMq6ne2WeeBuvjgKFLZb_G5Vmo,963
|
|
2
2
|
PyPDFForm/adapter.py,sha256=LBxHth0qJFB6rdByRJbsn4x0dftCOAolKVutZeFZm9E,2634
|
|
3
3
|
PyPDFForm/constants.py,sha256=tFtomm4bSsghxRqKaMP6Tln7ug9W_72e-AAU3sEU_no,2917
|
|
4
4
|
PyPDFForm/coordinate.py,sha256=veYOlRyFKIvzLISYA_f-drNBiKOzFwr0EIFCaUAzGgo,4428
|
|
5
5
|
PyPDFForm/filler.py,sha256=fqGIxT3FR3cWo3SMTDYud6Ocs9SZBmSpFv5yg1v19Wk,8450
|
|
6
6
|
PyPDFForm/font.py,sha256=TkiGPHIf4NxDiDzkrlXIr1r-DZC1V4aYrQAzGFxBlLI,13423
|
|
7
|
-
PyPDFForm/hooks.py,sha256=
|
|
7
|
+
PyPDFForm/hooks.py,sha256=SFE7YlZQQpra7A2D_4ITU1TzGyfiqJk3mQUVfQHu8Bg,16210
|
|
8
8
|
PyPDFForm/image.py,sha256=P1P3Ejm8PVPQwpJFGAesjtwS5hxnVItrj75TE3WnFhM,4607
|
|
9
|
-
PyPDFForm/patterns.py,sha256=
|
|
10
|
-
PyPDFForm/template.py,sha256=
|
|
9
|
+
PyPDFForm/patterns.py,sha256=CjZBv5nGfJ1NmAiwfsvRTwEQ-v5U8S6vrUlrUaAAyP0,10621
|
|
10
|
+
PyPDFForm/template.py,sha256=IQ5iPcAIeKNnNcv_eYqjcid-1CtQdNQtN4vu4F3pPBU,11362
|
|
11
11
|
PyPDFForm/utils.py,sha256=JavhAO4HmYRdujlsPXcZWGXTf7wDXzj4uU1XGRFsAaA,13257
|
|
12
12
|
PyPDFForm/watermark.py,sha256=BJ8NeZLKf-MuJ2XusHiALaQpoqE8j6hHGbWcNhpjxN0,11299
|
|
13
13
|
PyPDFForm/wrapper.py,sha256=_KKE2jUBcXxnkMzL8T43JjMmf8fvuJ-TTmYEy_h7h-c,30603
|
|
@@ -28,8 +28,8 @@ PyPDFForm/widgets/image.py,sha256=SegpzNjTXPuWX4hk_20yKk_IDaOrc81X9b9B4qK-kME,16
|
|
|
28
28
|
PyPDFForm/widgets/radio.py,sha256=pSOAgOakGAoi-190pFklMmLClFdPCWMDYWW1Ce6q__g,3933
|
|
29
29
|
PyPDFForm/widgets/signature.py,sha256=yye_CLYpgurLJ_rt7Td3xaY28uSAHc1YlqL1gmWqPqw,6034
|
|
30
30
|
PyPDFForm/widgets/text.py,sha256=EG2mR-POHGWt9I-t3QVsTFIiDB5yqKPDBTKkAytQGp8,3836
|
|
31
|
-
pypdfform-3.5.
|
|
32
|
-
pypdfform-3.5.
|
|
33
|
-
pypdfform-3.5.
|
|
34
|
-
pypdfform-3.5.
|
|
35
|
-
pypdfform-3.5.
|
|
31
|
+
pypdfform-3.5.2.dist-info/licenses/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
|
|
32
|
+
pypdfform-3.5.2.dist-info/METADATA,sha256=UzNH_wWYUjaKHbD-V5mpLVA9HbyHp4-8Ghze4UntJdQ,4267
|
|
33
|
+
pypdfform-3.5.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
34
|
+
pypdfform-3.5.2.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
|
|
35
|
+
pypdfform-3.5.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|