PyPDFForm 1.5.0__py3-none-any.whl → 1.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 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.2"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper
7
7
 
PyPDFForm/adapter.py CHANGED
@@ -12,7 +12,7 @@ def readable(obj: Any) -> bool:
12
12
 
13
13
 
14
14
  def fp_or_f_obj_or_stream_to_stream(
15
- fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO]
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
 
PyPDFForm/constants.py CHANGED
@@ -76,11 +76,11 @@ NEW_LINE_SYMBOL = "\n"
76
76
  IMAGE_FIELD_IDENTIFIER = "event.target.buttonImportIcon();"
77
77
 
78
78
  DEFAULT_CHECKBOX_STYLE = "\u2713"
79
- DEFAULT_RADIO_STYLE = "\u25CF"
79
+ DEFAULT_RADIO_STYLE = "\u25cf"
80
80
  BUTTON_STYLES = {
81
81
  "4": "\u2713", # check
82
- "5": "\u00D7", # cross
83
- "l": "\u25CF", # circle
82
+ "5": "\u00d7", # cross
83
+ "l": "\u25cf", # circle
84
84
  }
85
85
 
86
86
  COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO = DEFAULT_FONT_SIZE / 100
@@ -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:
@@ -71,6 +71,13 @@ class FormWrapper:
71
71
  class PdfWrapper(FormWrapper):
72
72
  """A class to represent a PDF form."""
73
73
 
74
+ USER_PARAMS = [
75
+ "global_font",
76
+ "global_font_size",
77
+ "global_font_color",
78
+ "use_full_widget_name",
79
+ ]
80
+
74
81
  def __init__(
75
82
  self,
76
83
  template: Union[bytes, str, BinaryIO] = b"",
@@ -82,9 +89,8 @@ class PdfWrapper(FormWrapper):
82
89
  self.widgets = {}
83
90
  self._keys_to_update = []
84
91
 
85
- self.global_font = kwargs.get("global_font")
86
- self.global_font_size = kwargs.get("global_font_size")
87
- self.global_font_color = kwargs.get("global_font_color")
92
+ for each in self.USER_PARAMS:
93
+ setattr(self, each, kwargs.get(each))
88
94
 
89
95
  self._init_helper()
90
96
 
@@ -92,7 +98,11 @@ class PdfWrapper(FormWrapper):
92
98
  """Updates all attributes when the state of the PDF stream changes."""
93
99
 
94
100
  refresh_not_needed = {}
95
- new_widgets = build_widgets(self.read()) if self.read() else {}
101
+ new_widgets = (
102
+ build_widgets(self.read(), getattr(self, "use_full_widget_name"))
103
+ if self.read()
104
+ else {}
105
+ )
96
106
  for k, v in self.widgets.items():
97
107
  if k in new_widgets:
98
108
  new_widgets[k] = v
@@ -105,9 +115,9 @@ class PdfWrapper(FormWrapper):
105
115
  and isinstance(value, Text)
106
116
  and not refresh_not_needed.get(key)
107
117
  ):
108
- value.font = self.global_font
109
- value.font_size = self.global_font_size
110
- value.font_color = self.global_font_color
118
+ value.font = getattr(self, "global_font")
119
+ value.font_size = getattr(self, "global_font_size")
120
+ value.font_color = getattr(self, "global_font_color")
111
121
 
112
122
  @property
113
123
  def sample_data(self) -> dict:
@@ -129,7 +139,12 @@ class PdfWrapper(FormWrapper):
129
139
  def pages(self) -> List[PdfWrapper]:
130
140
  """Returns a list of pdf wrapper objects where each is a page of the PDF form."""
131
141
 
132
- return [self.__class__(each) for each in get_page_streams(self.stream)]
142
+ return [
143
+ self.__class__(
144
+ each, **{param: getattr(self, param) for param in self.USER_PARAMS}
145
+ )
146
+ for each in get_page_streams(self.stream)
147
+ ]
133
148
 
134
149
  def change_version(self, version: str) -> PdfWrapper:
135
150
  """Changes the version of the PDF."""
@@ -254,6 +269,9 @@ class PdfWrapper(FormWrapper):
254
269
  ) -> PdfWrapper:
255
270
  """Updates the key of an existed widget on a PDF form."""
256
271
 
272
+ if getattr(self, "use_full_widget_name"):
273
+ raise NotImplementedError
274
+
257
275
  if defer:
258
276
  self._keys_to_update.append((old_key, new_key, index))
259
277
  return self
@@ -268,6 +286,9 @@ class PdfWrapper(FormWrapper):
268
286
  def commit_widget_key_updates(self) -> PdfWrapper:
269
287
  """Commits all deferred widget key updates on a PDF form."""
270
288
 
289
+ if getattr(self, "use_full_widget_name"):
290
+ raise NotImplementedError
291
+
271
292
  old_keys = [each[0] for each in self._keys_to_update]
272
293
  new_keys = [each[1] for each in self._keys_to_update]
273
294
  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.2
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,17 +1,17 @@
1
- PyPDFForm/__init__.py,sha256=-JU9Sz_lN3p7mSfsgeNlTUs4CS28fueCscA5_Bhv3sg,178
2
- PyPDFForm/adapter.py,sha256=WFP-r8FLeKa-D9mFO9AphOcuXgyeAI1Ak0d-YsqxsK4,861
3
- PyPDFForm/constants.py,sha256=48mxgyY3UgiVO2UIZuDe_B8KOE5bedyujnOjk6MtzHQ,1749
1
+ PyPDFForm/__init__.py,sha256=-SiFL-rTPed5J5k_a2JG6rtcU_vGtAZigzoS-S_Sfmk,178
2
+ PyPDFForm/adapter.py,sha256=qt0lqd7zRzaMHD2As47oiIhungO3AyWbAkxx1ZAZi9A,862
3
+ PyPDFForm/constants.py,sha256=xj9CSq7PlCpAowKAlK0o8YPgPkBkJjRDToI8aiqC_c0,1749
4
4
  PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
5
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
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=dxcFnkMv7zwT75BWZxgbrpl-Ty1dB98gjiP6xp9ihAU,11565
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.2.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
+ PyPDFForm-1.5.2.dist-info/METADATA,sha256=15iix1PjDLJk3OLrQTFdKRpt-dmH2JaL-vcjWCuPksc,4376
28
+ PyPDFForm-1.5.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
+ PyPDFForm-1.5.2.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
+ PyPDFForm-1.5.2.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