PyPDFForm 1.4.35__py3-none-any.whl → 1.4.36__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 CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Contains any object users might need."""
3
3
 
4
- __version__ = "1.4.35"
4
+ __version__ = "1.4.36"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper
7
7
 
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 = signature_image_handler(
131
+ any_image_to_draw |= signature_image_handler(
132
132
  widget_dict, widgets[key], images_to_draw[page]
133
133
  )
134
134
  else:
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.35
3
+ Version: 1.4.36
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -1,15 +1,15 @@
1
- PyPDFForm/__init__.py,sha256=9dfihKc09ZglJuveuHbEH6vycHLDKZba-wMkcRdv3zI,179
1
+ PyPDFForm/__init__.py,sha256=piytcpUIHLfdyWTQOM9ZDn1CgeF0GlRVciqihHGpihQ,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=pgMA7EC8axKUganmbk7X1uDdsb4OQQFoiI85td3pOO4,7486
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=9DFI-2cVZxzJKWmWBjK-dRSeAMNQr7ovHmw1YevrkiQ,5028
9
- PyPDFForm/template.py,sha256=a9rDzhHHfnYFo8cDnHnRE9UriUykXvrsyFKVGq9DYd0,13166
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=EC5ugli6Nj1q0un8je3f5xtRIfIxDSf9YrG50QipTPk,9715
12
+ PyPDFForm/wrapper.py,sha256=PRtiLJAtO3Sbpvr3qDy1ElitSRcNghpbkwSSiCMQ-7E,10231
13
13
  PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  PyPDFForm/middleware/base.py,sha256=p-3XsZJ6d7ai2JFLF7LisMWi9yzM3pN7CsFECxtEoI0,751
15
15
  PyPDFForm/middleware/checkbox.py,sha256=3-9CMhhtyO9U6lLXDciW-59ng8uS4m6_clPB02mzV9c,1317
@@ -23,8 +23,8 @@ PyPDFForm/widgets/base.py,sha256=nb6HEfRdWSjZc_Th1XI62PIlgREn_JiApGC-epb6jAg,334
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.35.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
- PyPDFForm-1.4.35.dist-info/METADATA,sha256=NGXpVEkFdAFv0SY4Di2p8JBEiEJLcmbD9-LCFLO-RTo,4151
28
- PyPDFForm-1.4.35.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
- PyPDFForm-1.4.35.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
- PyPDFForm-1.4.35.dist-info/RECORD,,
26
+ PyPDFForm-1.4.36.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
+ PyPDFForm-1.4.36.dist-info/METADATA,sha256=bDAjb3toOHXX-5hMPJQSWEzzcMDRoHCOkYgDWoxh4hM,4151
28
+ PyPDFForm-1.4.36.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
29
+ PyPDFForm-1.4.36.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
+ PyPDFForm-1.4.36.dist-info/RECORD,,