PyPDFForm 1.5.4__py3-none-any.whl → 1.5.6__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.4"
4
+ __version__ = "1.5.6"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper
7
7
 
PyPDFForm/constants.py CHANGED
@@ -84,6 +84,7 @@ BUTTON_STYLES = {
84
84
  }
85
85
 
86
86
  COORDINATE_GRID_FONT_SIZE_MARGIN_RATIO = DEFAULT_FONT_SIZE / 100
87
+ UNIQUE_SUFFIX_LENGTH = 20
87
88
 
88
89
  # Used for adjusting paragraph font size
89
90
  FONT_SIZE_REDUCE_STEP = 0.5
PyPDFForm/filler.py CHANGED
@@ -13,7 +13,7 @@ from .coordinate import (get_draw_checkbox_radio_coordinates,
13
13
  get_draw_text_coordinates,
14
14
  get_text_line_x_coordinates)
15
15
  from .font import checkbox_radio_font_size
16
- from .image import any_image_to_jpg, get_image_dimensions
16
+ from .image import get_image_dimensions
17
17
  from .middleware.checkbox import Checkbox
18
18
  from .middleware.dropdown import Dropdown
19
19
  from .middleware.image import Image
@@ -61,7 +61,6 @@ def signature_image_handler(
61
61
  any_image_to_draw = False
62
62
  if stream is not None:
63
63
  any_image_to_draw = True
64
- stream = any_image_to_jpg(stream)
65
64
  image_width, image_height = get_image_dimensions(stream)
66
65
  x, y, width, height = get_draw_image_coordinates_resolutions(
67
66
  widget, middleware.preserve_aspect_ratio, image_width, image_height
PyPDFForm/image.py CHANGED
@@ -38,28 +38,3 @@ def get_image_dimensions(image_stream: bytes) -> Tuple[float, float]:
38
38
  image = Image.open(buff)
39
39
 
40
40
  return image.size
41
-
42
-
43
- def any_image_to_jpg(image_stream: bytes) -> bytes:
44
- """Converts an image of any type to jpg."""
45
-
46
- buff = BytesIO()
47
- buff.write(image_stream)
48
- buff.seek(0)
49
-
50
- image = Image.open(buff)
51
-
52
- if image.format == "JPEG":
53
- buff.close()
54
- return image_stream
55
-
56
- rgb_image = Image.new("RGB", image.size, (255, 255, 255))
57
- rgb_image.paste(image, mask=image.split()[3] if len(image.split()) == 4 else None)
58
-
59
- with BytesIO() as _file:
60
- rgb_image.save(_file, format="JPEG")
61
- _file.seek(0)
62
- result = _file.read()
63
-
64
- buff.close()
65
- return result
PyPDFForm/utils.py CHANGED
@@ -2,6 +2,8 @@
2
2
  """Contains utility helpers."""
3
3
 
4
4
  from io import BytesIO
5
+ from secrets import choice
6
+ from string import ascii_letters, digits, punctuation
5
7
  from typing import BinaryIO, List, Union
6
8
 
7
9
  from pypdf import PdfReader, PdfWriter
@@ -9,7 +11,8 @@ from pypdf.generic import DictionaryObject
9
11
 
10
12
  from .constants import (BUTTON_STYLES, DEFAULT_CHECKBOX_STYLE, DEFAULT_FONT,
11
13
  DEFAULT_FONT_COLOR, DEFAULT_FONT_SIZE,
12
- DEFAULT_RADIO_STYLE, PREVIEW_FONT_COLOR, WIDGET_TYPES)
14
+ DEFAULT_RADIO_STYLE, PREVIEW_FONT_COLOR,
15
+ UNIQUE_SUFFIX_LENGTH, WIDGET_TYPES)
13
16
  from .middleware.checkbox import Checkbox
14
17
  from .middleware.radio import Radio
15
18
  from .middleware.text import Text
@@ -150,3 +153,14 @@ def traverse_pattern(
150
153
  if result:
151
154
  return result
152
155
  return None
156
+
157
+
158
+ def generate_unique_suffix() -> str:
159
+ """Generates a unique suffix string for widgets during form merging."""
160
+
161
+ return "".join(
162
+ [
163
+ choice(ascii_letters + digits + punctuation.replace("-", ""))
164
+ for _ in range(UNIQUE_SUFFIX_LENGTH)
165
+ ]
166
+ )
PyPDFForm/watermark.py CHANGED
@@ -122,6 +122,7 @@ def draw_image(*args) -> None:
122
122
  coordinate_y,
123
123
  width=width,
124
124
  height=height,
125
+ mask="auto",
125
126
  )
126
127
 
127
128
  image_buff.close()
PyPDFForm/wrapper.py CHANGED
@@ -13,14 +13,14 @@ from .constants import (DEFAULT_FONT, DEFAULT_FONT_COLOR, DEFAULT_FONT_SIZE,
13
13
  from .coordinate import generate_coordinate_grid
14
14
  from .filler import fill, simple_fill
15
15
  from .font import register_font
16
- from .image import any_image_to_jpg, rotate_image
16
+ from .image import rotate_image
17
17
  from .middleware.dropdown import Dropdown
18
18
  from .middleware.text import Text
19
19
  from .template import (build_widgets, dropdown_to_text,
20
20
  set_character_x_paddings, update_text_field_attributes,
21
21
  update_widget_keys, widget_rect_watermarks)
22
- from .utils import (get_page_streams, merge_two_pdfs, preview_widget_to_draw,
23
- remove_all_widgets)
22
+ from .utils import (generate_unique_suffix, get_page_streams, merge_two_pdfs,
23
+ preview_widget_to_draw, remove_all_widgets)
24
24
  from .watermark import create_watermarks_and_draw, merge_watermarks_with_pdf
25
25
  from .widgets.base import handle_non_acro_form_params
26
26
  from .widgets.checkbox import CheckBoxWidget
@@ -166,9 +166,10 @@ class PdfWrapper(FormWrapper):
166
166
  if not other.stream:
167
167
  return self
168
168
 
169
+ unique_suffix = generate_unique_suffix()
169
170
  for k in self.widgets:
170
171
  if k in other.widgets:
171
- other.update_widget_key(k, f"{k}-{id(other)}", defer=True)
172
+ other.update_widget_key(k, f"{k}-{unique_suffix}", defer=True)
172
173
 
173
174
  other.commit_widget_key_updates()
174
175
 
@@ -353,7 +354,6 @@ class PdfWrapper(FormWrapper):
353
354
  """Draws an image on a PDF form."""
354
355
 
355
356
  image = fp_or_f_obj_or_stream_to_stream(image)
356
- image = any_image_to_jpg(image)
357
357
  image = rotate_image(image, rotation)
358
358
  watermarks = create_watermarks_and_draw(
359
359
  self.stream, page_number, "image", [[image, x, y, width, height]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: PyPDFForm
3
- Version: 1.5.4
3
+ Version: 1.5.6
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=7kE_CzxALB37_zXnvY-D6uR_PPuFMpPVucShuQjQOCk,178
1
+ PyPDFForm/__init__.py,sha256=8onImOXUVxYFLD0V7_lKqLrFSh0joz4139XMS03cWKQ,178
2
2
  PyPDFForm/adapter.py,sha256=qt0lqd7zRzaMHD2As47oiIhungO3AyWbAkxx1ZAZi9A,862
3
- PyPDFForm/constants.py,sha256=xj9CSq7PlCpAowKAlK0o8YPgPkBkJjRDToI8aiqC_c0,1749
3
+ PyPDFForm/constants.py,sha256=iHCwbnypwgMe5T_hMZIJJixySkOlXgtXuNlI2UUptJ8,1775
4
4
  PyPDFForm/coordinate.py,sha256=uZGGFiTUIrD9VX-bzgUpKlFAzK7VJppW1corGXvT-pY,7712
5
- PyPDFForm/filler.py,sha256=wPVd6lwCPyZ8qPIKK1rLlKFLEWWPcYNPjuXqpC04Cws,7657
5
+ PyPDFForm/filler.py,sha256=BWj3CpRWTrNCNBrMMptdxW9Nac6pnQCl3xOw5l0QPy8,7597
6
6
  PyPDFForm/font.py,sha256=TbFLY4G72d7cQ3VG2g4HaYKROzQPQUmh6-8ynN6hzXY,5713
7
- PyPDFForm/image.py,sha256=SflPlzoTFZro2Fvd7u7bF-1mmg7D0e8YjePbQXW8YyY,1429
7
+ PyPDFForm/image.py,sha256=IsmT2_LAvoGTxbsrelXnP8B4vUKetOVwp6oiE9MGnU8,835
8
8
  PyPDFForm/patterns.py,sha256=Z548TjpQpaVepctvlRYe0-2i7Aws96fo-ncG82CUX14,5423
9
9
  PyPDFForm/template.py,sha256=LlnZTNF5UPLkiGqnSgHNcVr_Af6vJyg6vBf7jVD5wAM,15470
10
- PyPDFForm/utils.py,sha256=9omR-oT3OdZqioxpiGqA9_P0GSFC6mg4Y1xrLvWOzkk,4309
11
- PyPDFForm/watermark.py,sha256=L4LfzjjyJ6TDq9ad2dbtQYheBOic1_oZ7smhFFekNog,4725
12
- PyPDFForm/wrapper.py,sha256=tbmJIwvu4anaol7wQpmWL908CC04d_IAVRfE39K3y6k,11697
10
+ PyPDFForm/utils.py,sha256=hMWGLyTZJSQG4gItlnQLq8RxnV4bM2sL6_-RmLqSwtE,4721
11
+ PyPDFForm/watermark.py,sha256=eDGQKXc4j1uUhAAE1VeQXGHQ9FO4h9mSKExv3gnNTZg,4746
12
+ PyPDFForm/wrapper.py,sha256=fxvwP-bGqq7yAFjUr4PtHBUVU_f0cdrQMtmamOPrk5s,11716
13
13
  PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  PyPDFForm/middleware/base.py,sha256=Sjo8O9RrdBu73r4BCMPuLXnrl1hzjb1dlTOPeIgrhOU,1150
15
15
  PyPDFForm/middleware/checkbox.py,sha256=0EWFECXYdz9SNxgGe1QCcRrdxLVUIJpzRYwKfGRA9e4,1346
@@ -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.4.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
- pypdfform-1.5.4.dist-info/METADATA,sha256=4FkB1rXuP42Wz06oxGdgDYtGOweJ8ddfFEUz74tyQZE,4376
28
- pypdfform-1.5.4.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
29
- pypdfform-1.5.4.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
- pypdfform-1.5.4.dist-info/RECORD,,
26
+ pypdfform-1.5.6.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
+ pypdfform-1.5.6.dist-info/METADATA,sha256=oO2397bLIYzKMC1VboqZpQM5oyzBP3-2_7HM-LACuoo,4376
28
+ pypdfform-1.5.6.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
29
+ pypdfform-1.5.6.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
+ pypdfform-1.5.6.dist-info/RECORD,,