PyPDFForm 1.4.35__py3-none-any.whl → 1.4.37__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/filler.py +1 -1
- PyPDFForm/middleware/base.py +13 -1
- PyPDFForm/middleware/text.py +17 -0
- PyPDFForm/patterns.py +9 -0
- PyPDFForm/template.py +47 -4
- PyPDFForm/wrapper.py +17 -1
- {PyPDFForm-1.4.35.dist-info → PyPDFForm-1.4.37.dist-info}/METADATA +2 -1
- {PyPDFForm-1.4.35.dist-info → PyPDFForm-1.4.37.dist-info}/RECORD +12 -12
- {PyPDFForm-1.4.35.dist-info → PyPDFForm-1.4.37.dist-info}/WHEEL +1 -1
- {PyPDFForm-1.4.35.dist-info → PyPDFForm-1.4.37.dist-info}/LICENSE +0 -0
- {PyPDFForm-1.4.35.dist-info → PyPDFForm-1.4.37.dist-info}/top_level.txt +0 -0
PyPDFForm/__init__.py
CHANGED
PyPDFForm/filler.py
CHANGED
|
@@ -128,7 +128,7 @@ def fill(
|
|
|
128
128
|
widget_dict, widgets[key], radio_button_tracker
|
|
129
129
|
)
|
|
130
130
|
elif isinstance(widgets[key], (Signature, Image)):
|
|
131
|
-
any_image_to_draw
|
|
131
|
+
any_image_to_draw |= signature_image_handler(
|
|
132
132
|
widget_dict, widgets[key], images_to_draw[page]
|
|
133
133
|
)
|
|
134
134
|
else:
|
PyPDFForm/middleware/base.py
CHANGED
|
@@ -16,7 +16,7 @@ class Widget:
|
|
|
16
16
|
|
|
17
17
|
super().__init__()
|
|
18
18
|
self._name = name
|
|
19
|
-
self.
|
|
19
|
+
self._value = value
|
|
20
20
|
|
|
21
21
|
@property
|
|
22
22
|
def name(self) -> str:
|
|
@@ -24,6 +24,18 @@ class Widget:
|
|
|
24
24
|
|
|
25
25
|
return self._name
|
|
26
26
|
|
|
27
|
+
@property
|
|
28
|
+
def value(self) -> Any:
|
|
29
|
+
"""Value to fill for the widget."""
|
|
30
|
+
|
|
31
|
+
return self._value
|
|
32
|
+
|
|
33
|
+
@value.setter
|
|
34
|
+
def value(self, value: Any) -> None:
|
|
35
|
+
"""Sets value to fill for the widget."""
|
|
36
|
+
|
|
37
|
+
self._value = value
|
|
38
|
+
|
|
27
39
|
@property
|
|
28
40
|
def schema_definition(self) -> dict:
|
|
29
41
|
"""Json schema definition of the widget."""
|
PyPDFForm/middleware/text.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""Contains text middleware."""
|
|
3
3
|
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
4
6
|
from .base import Widget
|
|
5
7
|
|
|
6
8
|
|
|
@@ -27,6 +29,21 @@ class Text(Widget):
|
|
|
27
29
|
self.text_line_x_coordinates = None
|
|
28
30
|
self.preview = False
|
|
29
31
|
|
|
32
|
+
@property
|
|
33
|
+
def value(self) -> Any:
|
|
34
|
+
"""Value to fill for the text field."""
|
|
35
|
+
|
|
36
|
+
if isinstance(self._value, (int, float)):
|
|
37
|
+
return str(self._value)
|
|
38
|
+
|
|
39
|
+
return self._value
|
|
40
|
+
|
|
41
|
+
@value.setter
|
|
42
|
+
def value(self, value: str) -> None:
|
|
43
|
+
"""Sets value to fill for the text field."""
|
|
44
|
+
|
|
45
|
+
self._value = value
|
|
46
|
+
|
|
30
47
|
@property
|
|
31
48
|
def schema_definition(self) -> dict:
|
|
32
49
|
"""Json schema definition of the text field."""
|
PyPDFForm/patterns.py
CHANGED
|
@@ -160,6 +160,15 @@ def simple_flatten_generic(annot: DictionaryObject) -> None:
|
|
|
160
160
|
)
|
|
161
161
|
|
|
162
162
|
|
|
163
|
+
def update_annotation_name(annot: DictionaryObject, val: str) -> None:
|
|
164
|
+
"""Patterns to update the name of an annotation."""
|
|
165
|
+
|
|
166
|
+
if Parent in annot and T not in annot:
|
|
167
|
+
annot[NameObject(Parent)][NameObject(T)] = TextStringObject(val) # noqa
|
|
168
|
+
else:
|
|
169
|
+
annot[NameObject(T)] = TextStringObject(val) # noqa
|
|
170
|
+
|
|
171
|
+
|
|
163
172
|
def update_created_text_field_alignment(annot: DictionaryObject, val: int) -> None:
|
|
164
173
|
"""Patterns to update text alignment for text annotations created by the library."""
|
|
165
174
|
|
PyPDFForm/template.py
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
"""Contains helpers for generic template related processing."""
|
|
3
3
|
|
|
4
4
|
from functools import lru_cache
|
|
5
|
+
from io import BytesIO
|
|
5
6
|
from sys import maxsize
|
|
6
|
-
from typing import Dict, List, Tuple, Union
|
|
7
|
+
from typing import Dict, List, Tuple, Union, cast
|
|
7
8
|
|
|
8
|
-
from pypdf import PdfReader
|
|
9
|
+
from pypdf import PdfReader, PdfWriter
|
|
10
|
+
from pypdf.generic import DictionaryObject
|
|
9
11
|
from reportlab.pdfbase.pdfmetrics import stringWidth
|
|
10
12
|
|
|
11
13
|
from .constants import (COMB, DEFAULT_FONT_SIZE, MULTILINE, NEW_LINE_SYMBOL,
|
|
12
|
-
WIDGET_TYPES, MaxLen, Rect)
|
|
14
|
+
WIDGET_TYPES, Annots, MaxLen, Rect)
|
|
13
15
|
from .font import (adjust_paragraph_font_size, adjust_text_field_font_size,
|
|
14
16
|
auto_detect_font, get_text_field_font_color,
|
|
15
17
|
get_text_field_font_size, text_field_font_size)
|
|
@@ -19,7 +21,8 @@ from .middleware.radio import Radio
|
|
|
19
21
|
from .middleware.text import Text
|
|
20
22
|
from .patterns import (BUTTON_STYLE_PATTERNS, DROPDOWN_CHOICE_PATTERNS,
|
|
21
23
|
TEXT_FIELD_FLAG_PATTERNS, WIDGET_ALIGNMENT_PATTERNS,
|
|
22
|
-
WIDGET_KEY_PATTERNS, WIDGET_TYPE_PATTERNS
|
|
24
|
+
WIDGET_KEY_PATTERNS, WIDGET_TYPE_PATTERNS,
|
|
25
|
+
update_annotation_name)
|
|
23
26
|
from .utils import find_pattern_match, stream_to_io, traverse_pattern
|
|
24
27
|
from .watermark import create_watermarks_and_draw
|
|
25
28
|
|
|
@@ -403,3 +406,43 @@ def get_paragraph_auto_wrap_length(widget_middleware: Text) -> int:
|
|
|
403
406
|
result = min(result, len(line))
|
|
404
407
|
|
|
405
408
|
return result
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def update_widget_key(
|
|
412
|
+
template: bytes,
|
|
413
|
+
widgets: Dict[str, WIDGET_TYPES],
|
|
414
|
+
old_key: str,
|
|
415
|
+
new_key: str,
|
|
416
|
+
index: int,
|
|
417
|
+
) -> bytes:
|
|
418
|
+
"""Updates the key of a widget."""
|
|
419
|
+
# pylint: disable=R0801
|
|
420
|
+
|
|
421
|
+
pdf = PdfReader(stream_to_io(template))
|
|
422
|
+
out = PdfWriter()
|
|
423
|
+
out.append(pdf)
|
|
424
|
+
|
|
425
|
+
tracker = -1
|
|
426
|
+
|
|
427
|
+
for page in out.pages:
|
|
428
|
+
for annot in page.get(Annots, []): # noqa
|
|
429
|
+
annot = cast(DictionaryObject, annot.get_object())
|
|
430
|
+
key = get_widget_key(annot.get_object())
|
|
431
|
+
|
|
432
|
+
widget = widgets.get(key)
|
|
433
|
+
if widget is None:
|
|
434
|
+
continue
|
|
435
|
+
|
|
436
|
+
if old_key != key:
|
|
437
|
+
continue
|
|
438
|
+
|
|
439
|
+
tracker += 1
|
|
440
|
+
if not isinstance(widget, Radio) and tracker != index:
|
|
441
|
+
continue
|
|
442
|
+
|
|
443
|
+
update_annotation_name(annot, new_key)
|
|
444
|
+
|
|
445
|
+
with BytesIO() as f:
|
|
446
|
+
out.write(f)
|
|
447
|
+
f.seek(0)
|
|
448
|
+
return f.read()
|
PyPDFForm/wrapper.py
CHANGED
|
@@ -18,7 +18,7 @@ from .middleware.dropdown import Dropdown
|
|
|
18
18
|
from .middleware.text import Text
|
|
19
19
|
from .template import (build_widgets, dropdown_to_text,
|
|
20
20
|
set_character_x_paddings, update_text_field_attributes,
|
|
21
|
-
widget_rect_watermarks)
|
|
21
|
+
update_widget_key, widget_rect_watermarks)
|
|
22
22
|
from .utils import (get_page_streams, merge_two_pdfs, preview_widget_to_draw,
|
|
23
23
|
remove_all_widgets)
|
|
24
24
|
from .watermark import create_watermarks_and_draw, merge_watermarks_with_pdf
|
|
@@ -235,6 +235,22 @@ class PdfWrapper(FormWrapper):
|
|
|
235
235
|
|
|
236
236
|
return self
|
|
237
237
|
|
|
238
|
+
def update_widget_key(
|
|
239
|
+
self, old_key: str, new_key: str, index: int = 0
|
|
240
|
+
) -> PdfWrapper:
|
|
241
|
+
"""Updates the key of an existed widget on a PDF form."""
|
|
242
|
+
|
|
243
|
+
self.__init__(
|
|
244
|
+
template=update_widget_key(
|
|
245
|
+
self.read(), self.widgets, old_key, new_key, index
|
|
246
|
+
),
|
|
247
|
+
global_font=self.global_font,
|
|
248
|
+
global_font_size=self.global_font_size,
|
|
249
|
+
global_font_color=self.global_font_color,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
return self
|
|
253
|
+
|
|
238
254
|
def draw_text(
|
|
239
255
|
self,
|
|
240
256
|
text: str,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPDFForm
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.37
|
|
4
4
|
Summary: The Python library for PDF forms.
|
|
5
5
|
Home-page: https://github.com/chinapandaman/PyPDFForm
|
|
6
6
|
Author: Jinge Li
|
|
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
17
|
Classifier: License :: OSI Approved :: MIT License
|
|
17
18
|
Classifier: Operating System :: OS Independent
|
|
18
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
PyPDFForm/__init__.py,sha256=
|
|
1
|
+
PyPDFForm/__init__.py,sha256=c3mPBn4GLmtOK5zrTSR2Rn966Uj7N3n20D6rJnw0pC8,179
|
|
2
2
|
PyPDFForm/adapter.py,sha256=WFP-r8FLeKa-D9mFO9AphOcuXgyeAI1Ak0d-YsqxsK4,861
|
|
3
3
|
PyPDFForm/constants.py,sha256=FMsdOvnYpchEfki3gf_Y2Wj1SThUxMzsPbOx12_S1GA,1738
|
|
4
4
|
PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
|
|
5
|
-
PyPDFForm/filler.py,sha256=
|
|
5
|
+
PyPDFForm/filler.py,sha256=ztYU-Rk_LKfCw-BhmdIDnK7ez-5jSPoi2Ho3xvbO4Io,7487
|
|
6
6
|
PyPDFForm/font.py,sha256=TbFLY4G72d7cQ3VG2g4HaYKROzQPQUmh6-8ynN6hzXY,5713
|
|
7
7
|
PyPDFForm/image.py,sha256=sjXPg9fjenNFj12a321xHX6JvuJs6PJRGLzpSNw5mVU,1180
|
|
8
|
-
PyPDFForm/patterns.py,sha256=
|
|
9
|
-
PyPDFForm/template.py,sha256=
|
|
8
|
+
PyPDFForm/patterns.py,sha256=NluZyGSiKTV8ijqvBYSV8q389TuijI4wbv6fooHD6hk,5353
|
|
9
|
+
PyPDFForm/template.py,sha256=AaJ9qHw2Fw-51CRSfOy4POeEvFlKJ5h-WdqlFsGBuY4,14230
|
|
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=PRtiLJAtO3Sbpvr3qDy1ElitSRcNghpbkwSSiCMQ-7E,10231
|
|
13
13
|
PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
PyPDFForm/middleware/base.py,sha256=
|
|
14
|
+
PyPDFForm/middleware/base.py,sha256=GjBiFllppO5Xz8U8cEVBxrmK447bUivvrn_WX1IRow4,1005
|
|
15
15
|
PyPDFForm/middleware/checkbox.py,sha256=3-9CMhhtyO9U6lLXDciW-59ng8uS4m6_clPB02mzV9c,1317
|
|
16
16
|
PyPDFForm/middleware/dropdown.py,sha256=7_DuacMQCRvp2pYxDvzEjUNKDUsTfU0aGTRMBtYWTIA,692
|
|
17
17
|
PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
|
|
18
18
|
PyPDFForm/middleware/radio.py,sha256=ZDrRRF0Tu_3VBQ69x0G-IaZVf8FSOVz8xVpQsyiKhBc,725
|
|
19
19
|
PyPDFForm/middleware/signature.py,sha256=m7tNvGZ7fQ0yuVKzSlLbNQ2IILo1GDnjzMDzMnYCKVM,1104
|
|
20
|
-
PyPDFForm/middleware/text.py,sha256=
|
|
20
|
+
PyPDFForm/middleware/text.py,sha256=PSU-4u54NkefDRM-cMZ-3-hn-fVG6Q3_m3q8JS50dPE,1516
|
|
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.4.
|
|
27
|
-
PyPDFForm-1.4.
|
|
28
|
-
PyPDFForm-1.4.
|
|
29
|
-
PyPDFForm-1.4.
|
|
30
|
-
PyPDFForm-1.4.
|
|
26
|
+
PyPDFForm-1.4.37.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
|
|
27
|
+
PyPDFForm-1.4.37.dist-info/METADATA,sha256=pjzxkLQNmIdUgWis6c_CV4EvsRmlV33A5CWxZh2pvuE,4202
|
|
28
|
+
PyPDFForm-1.4.37.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
|
|
29
|
+
PyPDFForm-1.4.37.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
|
|
30
|
+
PyPDFForm-1.4.37.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|