PyPDFForm 1.4.15__py3-none-any.whl → 1.4.17__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,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Contains any object users might need."""
3
3
 
4
- __version__ = "1.4.15"
4
+ __version__ = "1.4.17"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper, PyPDFForm
PyPDFForm/constants.py CHANGED
@@ -37,6 +37,7 @@ Ff = "/Ff"
37
37
  Tx = "/Tx"
38
38
  V = "/V"
39
39
  AP = "/AP"
40
+ D = "/D"
40
41
  Sig = "/Sig"
41
42
  DA = "/DA"
42
43
  Btn = "/Btn"
@@ -47,6 +48,7 @@ Opt = "/Opt"
47
48
  MK = "/MK"
48
49
  CA = "/CA"
49
50
  AS = "/AS"
51
+ Off = "/Off"
50
52
 
51
53
  # Field flag bits
52
54
  READ_ONLY = 1 << 0
@@ -70,6 +72,4 @@ BUTTON_STYLES = {
70
72
  "l": "\u25CF", # circle
71
73
  }
72
74
 
73
- Yes = "/Yes"
74
-
75
75
  COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO = DEFAULT_FONT_SIZE / 100
PyPDFForm/filler.py CHANGED
@@ -158,7 +158,7 @@ def simple_fill(
158
158
  radio_button_tracker[key] = 0
159
159
  radio_button_tracker[key] += 1
160
160
  if widget.value == radio_button_tracker[key] - 1:
161
- simple_update_radio_value(annot, widget)
161
+ simple_update_radio_value(annot)
162
162
  elif isinstance(widget, Dropdown) and widget.value is not None:
163
163
  simple_update_dropdown_value(annot, widget)
164
164
  elif isinstance(widget, Text) and widget.value:
PyPDFForm/patterns.py CHANGED
@@ -4,8 +4,8 @@
4
4
  from pypdf.generic import (DictionaryObject, NameObject, NumberObject,
5
5
  TextStringObject)
6
6
 
7
- from .constants import (AP, AS, CA, DA, FT, MK, READ_ONLY, Btn, Ch, Ff, Opt,
8
- Parent, Q, Sig, Subtype, T, Tx, V, Widget, Yes)
7
+ from .constants import (AP, AS, CA, DA, FT, MK, READ_ONLY, Btn, Ch, D, Ff, Off,
8
+ Opt, Parent, Q, Sig, Subtype, T, Tx, V, Widget)
9
9
  from .middleware.checkbox import Checkbox
10
10
  from .middleware.dropdown import Dropdown
11
11
  from .middleware.radio import Radio
@@ -83,27 +83,45 @@ BUTTON_STYLE_PATTERNS = [
83
83
  def simple_update_checkbox_value(annot: DictionaryObject) -> None:
84
84
  """Patterns to update values for checkbox annotations."""
85
85
 
86
- annot[NameObject(AS)] = NameObject(Yes)
86
+ for each in annot[AP][D]: # noqa
87
+ if str(each) != Off:
88
+ annot[NameObject(AS)] = NameObject(each)
89
+ break
87
90
 
88
91
 
89
- def simple_update_radio_value(annot: DictionaryObject, widget: Radio) -> None:
92
+ def simple_update_radio_value(annot: DictionaryObject) -> None:
90
93
  """Patterns to update values for radio annotations."""
91
94
 
92
- annot[NameObject(AS)] = NameObject(f"/{widget.value}")
95
+ for each in annot[AP][D]: # noqa
96
+ if str(each) != Off:
97
+ annot[NameObject(AS)] = NameObject(each)
98
+ break
93
99
 
94
100
 
95
101
  def simple_update_dropdown_value(annot: DictionaryObject, widget: Dropdown) -> None:
96
102
  """Patterns to update values for dropdown annotations."""
97
103
 
98
- annot[NameObject(V)] = TextStringObject(widget.choices[widget.value])
99
- annot[NameObject(AP)] = TextStringObject(widget.choices[widget.value])
104
+ if Parent in annot and T not in annot:
105
+ annot[NameObject(Parent)][NameObject(V)] = TextStringObject( # noqa
106
+ widget.choices[widget.value]
107
+ )
108
+ annot[NameObject(AP)] = TextStringObject(widget.choices[widget.value])
109
+ else:
110
+ annot[NameObject(V)] = TextStringObject(widget.choices[widget.value])
111
+ annot[NameObject(AP)] = TextStringObject(widget.choices[widget.value])
100
112
 
101
113
 
102
114
  def simple_update_text_value(annot: DictionaryObject, widget: Text) -> None:
103
115
  """Patterns to update values for text annotations."""
104
116
 
105
- annot[NameObject(V)] = TextStringObject(widget.value)
106
- annot[NameObject(AP)] = TextStringObject(widget.value)
117
+ if Parent in annot and T not in annot:
118
+ annot[NameObject(Parent)][NameObject(V)] = TextStringObject( # noqa
119
+ widget.value
120
+ )
121
+ annot[NameObject(AP)] = TextStringObject(widget.value)
122
+ else:
123
+ annot[NameObject(V)] = TextStringObject(widget.value)
124
+ annot[NameObject(AP)] = TextStringObject(widget.value)
107
125
 
108
126
 
109
127
  def simple_flatten_radio(annot: DictionaryObject) -> None:
@@ -117,6 +135,11 @@ def simple_flatten_radio(annot: DictionaryObject) -> None:
117
135
  def simple_flatten_generic(annot: DictionaryObject) -> None:
118
136
  """Patterns to flatten generic annotations."""
119
137
 
120
- annot[NameObject(Ff)] = NumberObject(
121
- int(annot.get(NameObject(Ff), 0)) | READ_ONLY # noqa
122
- )
138
+ if Parent in annot and Ff not in annot:
139
+ annot[NameObject(Parent)][NameObject(Ff)] = NumberObject( # noqa
140
+ int(annot.get(NameObject(Ff), 0)) | READ_ONLY # noqa
141
+ )
142
+ else:
143
+ annot[NameObject(Ff)] = NumberObject(
144
+ int(annot.get(NameObject(Ff), 0)) | READ_ONLY # noqa
145
+ )
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Contains dropdown widget to create."""
3
+
4
+ from .base import Widget
5
+
6
+
7
+ class DropdownWidget(Widget):
8
+ """Dropdown widget to create."""
9
+
10
+ USER_PARAMS = [
11
+ ("width", "width"),
12
+ ("height", "height"),
13
+ ("options", "options"),
14
+ ("font", "fontName"),
15
+ ("font_size", "fontSize"),
16
+ ("font_color", "textColor"),
17
+ ]
18
+ COLOR_PARAMS = ["font_color"]
19
+ ACRO_FORM_FUNC = "_textfield"
20
+
21
+ def __init__(
22
+ self,
23
+ name: str,
24
+ page_number: int,
25
+ x: float,
26
+ y: float,
27
+ **kwargs,
28
+ ) -> None:
29
+ """Sets acro form parameters."""
30
+
31
+ super().__init__(name, page_number, x, y, **kwargs)
32
+ self.acro_form_params["wkind"] = "choice"
33
+ self.acro_form_params["value"] = self.acro_form_params["options"][0]
PyPDFForm/wrapper.py CHANGED
@@ -23,6 +23,7 @@ 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
25
25
  from .widgets.checkbox import CheckBoxWidget
26
+ from .widgets.dropdown import DropdownWidget
26
27
  from .widgets.text import TextWidget
27
28
 
28
29
 
@@ -218,6 +219,8 @@ class PdfWrapper(FormWrapper):
218
219
  _class = TextWidget
219
220
  if widget_type == "checkbox":
220
221
  _class = CheckBoxWidget
222
+ if widget_type == "dropdown":
223
+ _class = DropdownWidget
221
224
  if _class is None:
222
225
  return self
223
226
 
@@ -231,7 +234,7 @@ class PdfWrapper(FormWrapper):
231
234
  if k in new_widgets:
232
235
  new_widgets[k] = v
233
236
  self.widgets = new_widgets
234
- if widget_type == "text":
237
+ if widget_type in ("text", "dropdown"):
235
238
  self.widgets[name].font = self.global_font
236
239
  self.widgets[name].font_size = self.global_font_size
237
240
  self.widgets[name].font_color = self.global_font_color
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPDFForm
3
- Version: 1.4.15
3
+ Version: 1.4.17
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=KgGvTymkLYyv87kBq8HFehcC47PtgmzHc1zc73Z526w,149
1
+ PyPDFForm/__init__.py,sha256=z2mV0d3DO05R593oviGrHRIjaWnh4pMzMmVJJn_8QIk,149
2
2
  PyPDFForm/adapter.py,sha256=OgAIwcmukpBqHFBLymd3I7wA7wIdipRqgURZA2Y0Hgo,885
3
- PyPDFForm/constants.py,sha256=H-MBRnFhqvCrkVnwTCzYdt6ebe7rbUBTjzZl3GFdHtM,1431
3
+ PyPDFForm/constants.py,sha256=D2lIBZllCdEcLVsSZ6fRGxEYFaTZj9Ex7ksDxbs7g44,1439
4
4
  PyPDFForm/coordinate.py,sha256=iOy_KEZO3DKsvwdclxZHLOJyrvbCVqJDK2UKmMpEM8E,7310
5
- PyPDFForm/filler.py,sha256=qobLLpYF79YZaHmZz_VbjLICebg-6xdQa4btNZO4Li4,6430
5
+ PyPDFForm/filler.py,sha256=DdPGjVxkFNf1XqLmf-Qjr3xOFL0FX2afTCNC75JwJoc,6422
6
6
  PyPDFForm/font.py,sha256=y9vNvoaBfgkd5vz9EDp04ul8KDM2jY7J61-VWFng6GY,4155
7
7
  PyPDFForm/image.py,sha256=0GV8PFgY5oLJFHmhPD1fG-_5SBEO7jVLLtxCc_Uodfo,1143
8
- PyPDFForm/patterns.py,sha256=udF5Ka-ucEKgO13FvZ3VZv8mJbi-f-aAixAyJFR8cWI,2946
8
+ PyPDFForm/patterns.py,sha256=3m_lJ3LmlHY0TxiqrrQzjUCDqrZvhIp9NbMQV1OH28o,3827
9
9
  PyPDFForm/template.py,sha256=fuoqiYD_4xQXrBgw8XC677EMxJzHaXb9NcVVYbf0r-0,11782
10
10
  PyPDFForm/utils.py,sha256=_gskLLNmwhfGF16gfMP00twVY6iYADYYAYWHMvKCDrg,4140
11
11
  PyPDFForm/watermark.py,sha256=clYdRqCuWEE25IL-BUHnSo4HgLkHPSOl7FUJLhbAfGg,4755
12
- PyPDFForm/wrapper.py,sha256=oO-CYX_RzNm1O2bpifkpWUMzJ326TbR-EHTXmb6OCSc,10328
12
+ PyPDFForm/wrapper.py,sha256=RP-rk-jOWup4h7bXatKTnnA8yEtnHx-iK5Y6eN4--vg,10461
13
13
  PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  PyPDFForm/middleware/base.py,sha256=TmoO8XpjFa5NerAumrAGm_kUt2eFP3DyyF-Vx0uXloM,724
15
15
  PyPDFForm/middleware/checkbox.py,sha256=Z92awlKjceMd_ryb9Fhrtyd4fLkU84Ii6fSum60rHcA,1305
@@ -20,9 +20,10 @@ PyPDFForm/middleware/text.py,sha256=-ETNQoLvgu5cLkpIQtNYHtq75Ou3P7ezYur-E1yb9-k,
20
20
  PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  PyPDFForm/widgets/base.py,sha256=Stq-oQt-cfwQ6nilQ4NqpO5udFSKDNb1mAwryrWggZA,2076
22
22
  PyPDFForm/widgets/checkbox.py,sha256=issx3onojq9plTHbNQwEnkbnhTo5vJKA5XSAoxRzQCg,264
23
+ PyPDFForm/widgets/dropdown.py,sha256=Hzzevm6D0nOFdvZVjXchX4PYcvd_km_zkr8v_UDZKmM,824
23
24
  PyPDFForm/widgets/text.py,sha256=lUVlfQ-ndemSelsKNzY6nS4Kuf_H4mDPxotFMQFV-so,484
24
- PyPDFForm-1.4.15.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
25
- PyPDFForm-1.4.15.dist-info/METADATA,sha256=63tamlVBtPHyMvkegLhDXBGlZ2Wp9qMQ_HTLCRRC9_o,5178
26
- PyPDFForm-1.4.15.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
27
- PyPDFForm-1.4.15.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
28
- PyPDFForm-1.4.15.dist-info/RECORD,,
25
+ PyPDFForm-1.4.17.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
26
+ PyPDFForm-1.4.17.dist-info/METADATA,sha256=1MqVBDWRRKZbFjkxhaxv5hviZLVyeG6NM23cx1BLP38,5178
27
+ PyPDFForm-1.4.17.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
28
+ PyPDFForm-1.4.17.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
29
+ PyPDFForm-1.4.17.dist-info/RECORD,,