PyPDFForm 1.4.20__tar.gz → 1.4.21__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 (46) hide show
  1. {pypdfform-1.4.20 → pypdfform-1.4.21}/PKG-INFO +1 -1
  2. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/__init__.py +1 -1
  3. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/constants.py +4 -0
  4. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/coordinate.py +2 -2
  5. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/filler.py +6 -3
  6. pypdfform-1.4.21/PyPDFForm/middleware/image.py +8 -0
  7. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/patterns.py +8 -2
  8. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm.egg-info/PKG-INFO +1 -1
  9. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm.egg-info/SOURCES.txt +1 -0
  10. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_functional.py +18 -0
  11. {pypdfform-1.4.20 → pypdfform-1.4.21}/LICENSE +0 -0
  12. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/adapter.py +0 -0
  13. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/font.py +0 -0
  14. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/image.py +0 -0
  15. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/__init__.py +0 -0
  16. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/base.py +0 -0
  17. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/checkbox.py +0 -0
  18. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/dropdown.py +0 -0
  19. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/radio.py +0 -0
  20. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/signature.py +0 -0
  21. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/middleware/text.py +0 -0
  22. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/template.py +0 -0
  23. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/utils.py +0 -0
  24. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/watermark.py +0 -0
  25. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/widgets/__init__.py +0 -0
  26. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/widgets/base.py +0 -0
  27. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/widgets/checkbox.py +0 -0
  28. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/widgets/dropdown.py +0 -0
  29. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/widgets/text.py +0 -0
  30. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm/wrapper.py +0 -0
  31. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm.egg-info/dependency_links.txt +0 -0
  32. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm.egg-info/requires.txt +0 -0
  33. {pypdfform-1.4.20 → pypdfform-1.4.21}/PyPDFForm.egg-info/top_level.txt +0 -0
  34. {pypdfform-1.4.20 → pypdfform-1.4.21}/README.md +0 -0
  35. {pypdfform-1.4.20 → pypdfform-1.4.21}/setup.cfg +0 -0
  36. {pypdfform-1.4.20 → pypdfform-1.4.21}/setup.py +0 -0
  37. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_create_widget.py +0 -0
  38. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_dropdown.py +0 -0
  39. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_dropdown_simple.py +0 -0
  40. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_fill_max_length_text_field.py +0 -0
  41. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_fill_max_length_text_field_simple.py +0 -0
  42. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_functional_simple.py +0 -0
  43. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_paragraph.py +0 -0
  44. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_paragraph_simple.py +0 -0
  45. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_preview.py +0 -0
  46. {pypdfform-1.4.20 → pypdfform-1.4.21}/tests/test_signature.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPDFForm
3
- Version: 1.4.20
3
+ Version: 1.4.21
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.20"
4
+ __version__ = "1.4.21"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper, PyPDFForm
@@ -27,6 +27,8 @@ WIDGET_TYPES = Union[Text, Checkbox, Radio, Dropdown, Signature]
27
27
  DEPRECATION_NOTICE = "{} will be deprecated soon. Use {} instead."
28
28
 
29
29
  Annots = "/Annots"
30
+ A = "/A"
31
+ JS = "/JS"
30
32
  T = "/T"
31
33
  Rect = "/Rect"
32
34
  Subtype = "/Subtype"
@@ -64,6 +66,8 @@ PREVIEW_FONT_COLOR = (1, 0, 0)
64
66
 
65
67
  NEW_LINE_SYMBOL = "\n"
66
68
 
69
+ IMAGE_FIELD_IDENTIFIER = "event.target.buttonImportIcon();"
70
+
67
71
  DEFAULT_CHECKBOX_STYLE = "\u2713"
68
72
  DEFAULT_RADIO_STYLE = "\u25CF"
69
73
  BUTTON_STYLES = {
@@ -38,11 +38,11 @@ def get_draw_checkbox_radio_coordinates(
38
38
  )
39
39
 
40
40
 
41
- def get_draw_sig_coordinates_resolutions(
41
+ def get_draw_image_coordinates_resolutions(
42
42
  widget: dict,
43
43
  ) -> Tuple[float, float, float, float]:
44
44
  """
45
- Returns coordinates and resolutions to draw signature at given a PDF form signature widget.
45
+ Returns coordinates and resolutions to draw image at given a PDF form signature/image widget.
46
46
  """
47
47
 
48
48
  x = float(widget[Rect][0])
@@ -9,13 +9,14 @@ from pypdf.generic import DictionaryObject
9
9
 
10
10
  from .constants import WIDGET_TYPES, Annots
11
11
  from .coordinate import (get_draw_checkbox_radio_coordinates,
12
- get_draw_sig_coordinates_resolutions,
12
+ get_draw_image_coordinates_resolutions,
13
13
  get_draw_text_coordinates,
14
14
  get_text_line_x_coordinates)
15
15
  from .font import checkbox_radio_font_size
16
16
  from .image import any_image_to_jpg
17
17
  from .middleware.checkbox import Checkbox
18
18
  from .middleware.dropdown import Dropdown
19
+ from .middleware.image import Image
19
20
  from .middleware.radio import Radio
20
21
  from .middleware.signature import Signature
21
22
  from .middleware.text import Text
@@ -69,12 +70,14 @@ def fill(
69
70
  radio_button_tracker[key] += 1
70
71
  if widgets[key].value == radio_button_tracker[key] - 1:
71
72
  text_needs_to_be_drawn = True
72
- elif isinstance(widgets[key], Signature):
73
+ elif isinstance(widgets[key], (Signature, Image)):
73
74
  stream = widgets[key].stream
74
75
  if stream is not None:
75
76
  any_image_to_draw = True
76
77
  stream = any_image_to_jpg(stream)
77
- x, y, width, height = get_draw_sig_coordinates_resolutions(_widget)
78
+ x, y, width, height = get_draw_image_coordinates_resolutions(
79
+ _widget
80
+ )
78
81
  images_to_draw[page].append(
79
82
  [
80
83
  stream,
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Contains image field middleware."""
3
+
4
+ from .signature import Signature
5
+
6
+
7
+ class Image(Signature):
8
+ """A class to represent an image field widget."""
@@ -4,15 +4,21 @@
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, D, Ff, Off,
8
- Opt, Parent, Q, Sig, Subtype, T, Tx, V, Widget)
7
+ from .constants import (AP, AS, CA, DA, FT, IMAGE_FIELD_IDENTIFIER, JS, MK,
8
+ READ_ONLY, A, Btn, Ch, D, Ff, Off, Opt, Parent, Q, Sig,
9
+ Subtype, T, Tx, V, Widget)
9
10
  from .middleware.checkbox import Checkbox
10
11
  from .middleware.dropdown import Dropdown
12
+ from .middleware.image import Image
11
13
  from .middleware.radio import Radio
12
14
  from .middleware.signature import Signature
13
15
  from .middleware.text import Text
14
16
 
15
17
  WIDGET_TYPE_PATTERNS = [
18
+ (
19
+ ({A: {JS: IMAGE_FIELD_IDENTIFIER}},),
20
+ Image,
21
+ ),
16
22
  (
17
23
  ({FT: Sig},),
18
24
  Signature,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPDFForm
3
- Version: 1.4.20
3
+ Version: 1.4.21
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -22,6 +22,7 @@ PyPDFForm/middleware/__init__.py
22
22
  PyPDFForm/middleware/base.py
23
23
  PyPDFForm/middleware/checkbox.py
24
24
  PyPDFForm/middleware/dropdown.py
25
+ PyPDFForm/middleware/image.py
25
26
  PyPDFForm/middleware/radio.py
26
27
  PyPDFForm/middleware/signature.py
27
28
  PyPDFForm/middleware/text.py
@@ -610,3 +610,21 @@ def test_radio_change_size_and_button_style(
610
610
 
611
611
  assert len(obj.read()) == len(expected)
612
612
  assert obj.stream == expected
613
+
614
+
615
+ def test_fill_image(
616
+ sample_template_with_image_field, image_samples, pdf_samples, request
617
+ ):
618
+ expected_path = os.path.join(pdf_samples, "sample_filled_image.pdf")
619
+ with open(expected_path, "rb+") as f:
620
+ obj = PdfWrapper(sample_template_with_image_field).fill(
621
+ {"image_1": os.path.join(image_samples, "sample_image.jpg")},
622
+ )
623
+
624
+ request.config.results["expected_path"] = expected_path
625
+ request.config.results["stream"] = obj.read()
626
+
627
+ expected = f.read()
628
+
629
+ assert len(obj.read()) == len(expected)
630
+ assert obj.stream == expected
File without changes
File without changes
File without changes
File without changes
File without changes