PyPDFForm 1.5.0__py3-none-any.whl → 1.5.1__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.5.0"
4
+ __version__ = "1.5.1"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper
7
7
 
@@ -16,6 +16,7 @@ class Widget:
16
16
 
17
17
  super().__init__()
18
18
  self._name = name
19
+ self.full_name = None
19
20
  self._value = value
20
21
  self.desc = None
21
22
 
PyPDFForm/template.py CHANGED
@@ -11,7 +11,7 @@ from pypdf.generic import DictionaryObject
11
11
  from reportlab.pdfbase.pdfmetrics import stringWidth
12
12
 
13
13
  from .constants import (COMB, DEFAULT_FONT_SIZE, MULTILINE, NEW_LINE_SYMBOL,
14
- WIDGET_TYPES, Annots, MaxLen, Rect)
14
+ WIDGET_TYPES, Annots, MaxLen, Parent, Rect, T)
15
15
  from .font import (adjust_paragraph_font_size, adjust_text_field_font_size,
16
16
  auto_detect_font, get_text_field_font_color,
17
17
  get_text_field_font_size, text_field_font_size)
@@ -43,7 +43,9 @@ def set_character_x_paddings(
43
43
  return widgets
44
44
 
45
45
 
46
- def build_widgets(pdf_stream: bytes) -> Dict[str, WIDGET_TYPES]:
46
+ def build_widgets(
47
+ pdf_stream: bytes, use_full_widget_name: bool
48
+ ) -> Dict[str, WIDGET_TYPES]:
47
49
  """Builds a widget dict given a PDF form stream."""
48
50
 
49
51
  results = {}
@@ -53,6 +55,7 @@ def build_widgets(pdf_stream: bytes) -> Dict[str, WIDGET_TYPES]:
53
55
  key = get_widget_key(widget)
54
56
  _widget = construct_widget(widget, key)
55
57
  if _widget is not None:
58
+ _widget.full_name = get_widget_full_key(widget)
56
59
  _widget.desc = get_widget_description(widget)
57
60
  if isinstance(_widget, Text):
58
61
  _widget.max_length = get_text_field_max_length(widget)
@@ -73,6 +76,8 @@ def build_widgets(pdf_stream: bytes) -> Dict[str, WIDGET_TYPES]:
73
76
  continue
74
77
 
75
78
  results[key] = _widget
79
+ if _widget.full_name is not None and use_full_widget_name:
80
+ results[_widget.full_name] = results[key]
76
81
  return results
77
82
 
78
83
 
@@ -190,6 +195,24 @@ def get_widget_key(widget: dict) -> Union[str, list, None]:
190
195
  return result
191
196
 
192
197
 
198
+ def get_widget_full_key(widget: dict) -> Union[str, None]:
199
+ """
200
+ Returns a PDF widget's full annotated key by prepending its
201
+ parent widget's key.
202
+ """
203
+
204
+ key = get_widget_key(widget)
205
+
206
+ if (
207
+ Parent in widget
208
+ and T in widget[Parent].get_object()
209
+ and widget[Parent][T] != key
210
+ ):
211
+ return f"{widget[Parent][T]}.{key}"
212
+
213
+ return None
214
+
215
+
193
216
  def get_widget_alignment(widget: dict) -> Union[str, list, None]:
194
217
  """Finds a PDF widget's alignment by pattern matching."""
195
218
 
PyPDFForm/wrapper.py CHANGED
@@ -52,7 +52,7 @@ class FormWrapper:
52
52
  ) -> FormWrapper:
53
53
  """Fills a PDF form."""
54
54
 
55
- widgets = build_widgets(self.stream) if self.stream else {}
55
+ widgets = build_widgets(self.stream, False) if self.stream else {}
56
56
 
57
57
  for key, value in data.items():
58
58
  if key in widgets:
@@ -86,13 +86,17 @@ class PdfWrapper(FormWrapper):
86
86
  self.global_font_size = kwargs.get("global_font_size")
87
87
  self.global_font_color = kwargs.get("global_font_color")
88
88
 
89
+ self.use_full_widget_name = kwargs.get("use_full_widget_name", False)
90
+
89
91
  self._init_helper()
90
92
 
91
93
  def _init_helper(self, key_to_refresh: str = None) -> None:
92
94
  """Updates all attributes when the state of the PDF stream changes."""
93
95
 
94
96
  refresh_not_needed = {}
95
- new_widgets = build_widgets(self.read()) if self.read() else {}
97
+ new_widgets = (
98
+ build_widgets(self.read(), self.use_full_widget_name) if self.read() else {}
99
+ )
96
100
  for k, v in self.widgets.items():
97
101
  if k in new_widgets:
98
102
  new_widgets[k] = v
@@ -254,6 +258,9 @@ class PdfWrapper(FormWrapper):
254
258
  ) -> PdfWrapper:
255
259
  """Updates the key of an existed widget on a PDF form."""
256
260
 
261
+ if self.use_full_widget_name:
262
+ raise NotImplementedError
263
+
257
264
  if defer:
258
265
  self._keys_to_update.append((old_key, new_key, index))
259
266
  return self
@@ -268,6 +275,9 @@ class PdfWrapper(FormWrapper):
268
275
  def commit_widget_key_updates(self) -> PdfWrapper:
269
276
  """Commits all deferred widget key updates on a PDF form."""
270
277
 
278
+ if self.use_full_widget_name:
279
+ raise NotImplementedError
280
+
271
281
  old_keys = [each[0] for each in self._keys_to_update]
272
282
  new_keys = [each[1] for each in self._keys_to_update]
273
283
  indices = [each[2] for each in self._keys_to_update]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: PyPDFForm
3
- Version: 1.5.0
3
+ Version: 1.5.1
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -24,6 +24,14 @@ Requires-Dist: cryptography
24
24
  Requires-Dist: pillow
25
25
  Requires-Dist: pypdf
26
26
  Requires-Dist: reportlab
27
+ Dynamic: author
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: requires-dist
33
+ Dynamic: requires-python
34
+ Dynamic: summary
27
35
 
28
36
  <p align="center"><img src="https://github.com/chinapandaman/PyPDFForm/raw/master/logo.png"></p>
29
37
  <p align="center">
@@ -1,4 +1,4 @@
1
- PyPDFForm/__init__.py,sha256=-JU9Sz_lN3p7mSfsgeNlTUs4CS28fueCscA5_Bhv3sg,178
1
+ PyPDFForm/__init__.py,sha256=fM6oW3DZ3IPldn96No6E_Qf9uwf-R9ZkMZf54oZ2T-w,178
2
2
  PyPDFForm/adapter.py,sha256=WFP-r8FLeKa-D9mFO9AphOcuXgyeAI1Ak0d-YsqxsK4,861
3
3
  PyPDFForm/constants.py,sha256=48mxgyY3UgiVO2UIZuDe_B8KOE5bedyujnOjk6MtzHQ,1749
4
4
  PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
@@ -6,12 +6,12 @@ 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
8
  PyPDFForm/patterns.py,sha256=Z548TjpQpaVepctvlRYe0-2i7Aws96fo-ncG82CUX14,5423
9
- PyPDFForm/template.py,sha256=6cyuFieAyQM6S-x6Sasp7dLIb8aKwtlhlOgutjoX0ks,14839
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=n3qJVI3JRn-WKxq_CwC1tJw7AiI2Ltj8mvLDexK8U8s,11084
12
+ PyPDFForm/wrapper.py,sha256=QYGQrQs2VuvnRjrfxZfCeMxVj0gd6r_8Yi2RQ30NEQY,11375
13
13
  PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- PyPDFForm/middleware/base.py,sha256=xMg6X6-hJgvV-e_2rRJHBRO7gGICcBsnvUzxtF2XtVs,1120
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
17
  PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
@@ -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.5.0.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
- PyPDFForm-1.5.0.dist-info/METADATA,sha256=OzbNc9l4HTogbGqi45TaQzEGQaLr3sQStxf-84dI49Y,4201
28
- PyPDFForm-1.5.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
29
- PyPDFForm-1.5.0.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
- PyPDFForm-1.5.0.dist-info/RECORD,,
26
+ PyPDFForm-1.5.1.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
+ PyPDFForm-1.5.1.dist-info/METADATA,sha256=yHnhAICnAw0eO_IU3UwiuDIEF447E55A1PiO4CQCs9A,4376
28
+ PyPDFForm-1.5.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
+ PyPDFForm-1.5.1.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
+ PyPDFForm-1.5.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5