PyPDFForm 1.4.16__tar.gz → 1.4.18__tar.gz

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.

Files changed (45) hide show
  1. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PKG-INFO +1 -1
  2. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/__init__.py +1 -1
  3. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/filler.py +5 -5
  4. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/patterns.py +4 -2
  5. pypdfform-1.4.18/PyPDFForm/widgets/dropdown.py +33 -0
  6. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/wrapper.py +4 -1
  7. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm.egg-info/PKG-INFO +1 -1
  8. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm.egg-info/SOURCES.txt +1 -0
  9. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_create_widget.py +31 -0
  10. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_functional_simple.py +24 -0
  11. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/LICENSE +0 -0
  12. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/adapter.py +0 -0
  13. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/constants.py +0 -0
  14. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/coordinate.py +0 -0
  15. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/font.py +0 -0
  16. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/image.py +0 -0
  17. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/__init__.py +0 -0
  18. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/base.py +0 -0
  19. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/checkbox.py +0 -0
  20. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/dropdown.py +0 -0
  21. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/radio.py +0 -0
  22. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/signature.py +0 -0
  23. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/middleware/text.py +0 -0
  24. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/template.py +0 -0
  25. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/utils.py +0 -0
  26. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/watermark.py +0 -0
  27. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/widgets/__init__.py +0 -0
  28. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/widgets/base.py +0 -0
  29. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/widgets/checkbox.py +0 -0
  30. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm/widgets/text.py +0 -0
  31. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm.egg-info/dependency_links.txt +0 -0
  32. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm.egg-info/requires.txt +0 -0
  33. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/PyPDFForm.egg-info/top_level.txt +0 -0
  34. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/README.md +0 -0
  35. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/setup.cfg +0 -0
  36. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/setup.py +0 -0
  37. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_dropdown.py +0 -0
  38. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_dropdown_simple.py +0 -0
  39. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_fill_max_length_text_field.py +0 -0
  40. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_fill_max_length_text_field_simple.py +0 -0
  41. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_functional.py +0 -0
  42. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_paragraph.py +0 -0
  43. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_paragraph_simple.py +0 -0
  44. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_preview.py +0 -0
  45. {PyPDFForm-1.4.16 → pypdfform-1.4.18}/tests/test_signature.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPDFForm
3
- Version: 1.4.16
3
+ Version: 1.4.18
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Contains any object users might need."""
3
3
 
4
- __version__ = "1.4.16"
4
+ __version__ = "1.4.18"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper, PyPDFForm
@@ -148,20 +148,20 @@ def simple_fill(
148
148
  key = get_widget_key(annot.get_object())
149
149
 
150
150
  widget = widgets.get(key)
151
- if widget is None:
151
+ if widget is None or widget.value is None:
152
152
  continue
153
153
 
154
- if type(widget) is Checkbox and widget.value is True:
155
- simple_update_checkbox_value(annot)
154
+ if type(widget) is Checkbox:
155
+ simple_update_checkbox_value(annot, widget.value)
156
156
  elif isinstance(widget, Radio):
157
157
  if key not in radio_button_tracker:
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
161
  simple_update_radio_value(annot)
162
- elif isinstance(widget, Dropdown) and widget.value is not None:
162
+ elif isinstance(widget, Dropdown):
163
163
  simple_update_dropdown_value(annot, widget)
164
- elif isinstance(widget, Text) and widget.value:
164
+ elif isinstance(widget, Text):
165
165
  simple_update_text_value(annot, widget)
166
166
 
167
167
  if flatten:
@@ -80,12 +80,13 @@ BUTTON_STYLE_PATTERNS = [
80
80
  ]
81
81
 
82
82
 
83
- def simple_update_checkbox_value(annot: DictionaryObject) -> None:
83
+ def simple_update_checkbox_value(annot: DictionaryObject, check: bool = False) -> None:
84
84
  """Patterns to update values for checkbox annotations."""
85
85
 
86
86
  for each in annot[AP][D]: # noqa
87
- if str(each) != Off:
87
+ if (check and str(each) != Off) or (not check and str(each) == Off):
88
88
  annot[NameObject(AS)] = NameObject(each)
89
+ annot[NameObject(V)] = NameObject(each)
89
90
  break
90
91
 
91
92
 
@@ -95,6 +96,7 @@ def simple_update_radio_value(annot: DictionaryObject) -> None:
95
96
  for each in annot[AP][D]: # noqa
96
97
  if str(each) != Off:
97
98
  annot[NameObject(AS)] = NameObject(each)
99
+ annot[NameObject(Parent)][NameObject(V)] = NameObject(each) # noqa
98
100
  break
99
101
 
100
102
 
@@ -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]
@@ -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.16
3
+ Version: 1.4.18
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -28,6 +28,7 @@ PyPDFForm/middleware/text.py
28
28
  PyPDFForm/widgets/__init__.py
29
29
  PyPDFForm/widgets/base.py
30
30
  PyPDFForm/widgets/checkbox.py
31
+ PyPDFForm/widgets/dropdown.py
31
32
  PyPDFForm/widgets/text.py
32
33
  tests/test_create_widget.py
33
34
  tests/test_dropdown.py
@@ -342,3 +342,34 @@ def test_create_widget_sejda_schema(sejda_template):
342
342
 
343
343
  assert schema["properties"]["new_text_field_widget"]
344
344
  assert len(schema["properties"]) == 1
345
+
346
+
347
+ def test_create_dropdown(template_stream, pdf_samples, request):
348
+ expected_path = os.path.join(pdf_samples, "widget", "create_dropdown.pdf")
349
+ with open(expected_path, "rb+") as f:
350
+ obj = PdfWrapper(template_stream).create_widget(
351
+ widget_type="dropdown",
352
+ name="new_dropdown_widget",
353
+ page_number=1,
354
+ x=57,
355
+ y=700,
356
+ options=[
357
+ "foo",
358
+ "bar",
359
+ "foobar",
360
+ ],
361
+ width=120,
362
+ height=40,
363
+ font="Courier",
364
+ font_size=15,
365
+ font_color=(1, 0, 0),
366
+ )
367
+ assert obj.schema["properties"]["new_dropdown_widget"]["type"] == "integer"
368
+
369
+ request.config.results["expected_path"] = expected_path
370
+ request.config.results["stream"] = obj.read()
371
+
372
+ expected = f.read()
373
+
374
+ assert len(obj.stream) == len(expected)
375
+ assert obj.stream == expected
@@ -127,3 +127,27 @@ def test_fill_complex_fonts(sample_template_with_complex_fonts, pdf_samples, req
127
127
  if os.name != "nt":
128
128
  assert len(obj.read()) == len(expected)
129
129
  assert obj.stream == expected
130
+
131
+
132
+ def test_undo_checkbox(pdf_samples, request):
133
+ expected_path = os.path.join(
134
+ pdf_samples, "simple", "undo", "test_undo_checkbox.pdf"
135
+ )
136
+ with open(expected_path, "rb+") as f:
137
+ obj = FormWrapper(
138
+ os.path.join(pdf_samples, "simple", "undo", "sample_template_filled.pdf")
139
+ ).fill(
140
+ {
141
+ "check": False,
142
+ "check_2": False,
143
+ "check_3": False,
144
+ },
145
+ )
146
+
147
+ request.config.results["expected_path"] = expected_path
148
+ request.config.results["stream"] = obj.read()
149
+
150
+ expected = f.read()
151
+
152
+ assert len(obj.stream) == len(expected)
153
+ assert obj.stream == expected
File without changes
File without changes
File without changes
File without changes
File without changes