PyPDFForm 1.4.29__py3-none-any.whl → 1.4.31__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,8 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """Contains any object users might need."""
3
3
 
4
- __version__ = "1.4.29"
4
+ __version__ = "1.4.31"
5
5
 
6
6
  from .wrapper import FormWrapper, PdfWrapper
7
+
8
+ __all__ = ["FormWrapper", "PdfWrapper"]
PyPDFForm/adapter.py CHANGED
@@ -13,10 +13,10 @@ def readable(obj: Any) -> bool:
13
13
 
14
14
  def fp_or_f_obj_or_stream_to_stream(
15
15
  fp_or_f_obj_or_stream: Union[bytes, str, BinaryIO]
16
- ) -> Union[bytes, None]:
16
+ ) -> bytes:
17
17
  """Converts a file path or a file object to a stream."""
18
18
 
19
- result = None
19
+ result = b""
20
20
  if isinstance(fp_or_f_obj_or_stream, bytes):
21
21
  result = fp_or_f_obj_or_stream
22
22
 
@@ -25,8 +25,7 @@ def fp_or_f_obj_or_stream_to_stream(
25
25
 
26
26
  elif isinstance(fp_or_f_obj_or_stream, str):
27
27
  if not isfile(fp_or_f_obj_or_stream):
28
- result = None
29
-
28
+ pass
30
29
  else:
31
30
  with open(fp_or_f_obj_or_stream, "rb+") as _file:
32
31
  result = _file.read()
PyPDFForm/constants.py CHANGED
@@ -32,8 +32,6 @@ A = "/A"
32
32
  JS = "/JS"
33
33
  T = "/T"
34
34
  Rect = "/Rect"
35
- Subtype = "/Subtype"
36
- Widget = "/Widget"
37
35
  FT = "/FT"
38
36
  Parent = "/Parent"
39
37
  Ff = "/Ff"
@@ -43,6 +41,7 @@ AP = "/AP"
43
41
  N = "/N"
44
42
  Sig = "/Sig"
45
43
  DA = "/DA"
44
+ DV = "/DV"
46
45
  Btn = "/Btn"
47
46
  MaxLen = "/MaxLen"
48
47
  Q = "/Q"
PyPDFForm/font.py CHANGED
@@ -42,9 +42,9 @@ def extract_font_from_text_appearance(text_appearance: str) -> Union[str, None]:
42
42
  appearance string of a text field widget.
43
43
  """
44
44
 
45
- text_appearance = text_appearance.split(" ")
45
+ text_appearances = text_appearance.split(" ")
46
46
 
47
- for each in text_appearance:
47
+ for each in text_appearances:
48
48
  if each.startswith("/"):
49
49
  text_segments = findall("[A-Z][^A-Z]*", each.replace("/", ""))
50
50
 
@@ -14,6 +14,7 @@ class Widget:
14
14
  ) -> None:
15
15
  """Constructs basic attributes for the object."""
16
16
 
17
+ super().__init__()
17
18
  self._name = name
18
19
  self.value = value
19
20
 
@@ -34,7 +34,7 @@ class Checkbox(Widget):
34
34
  return {"type": "boolean"}
35
35
 
36
36
  @property
37
- def sample_value(self) -> bool:
37
+ def sample_value(self) -> Union[bool, int]:
38
38
  """Sample value of the checkbox."""
39
39
 
40
40
  return True
@@ -16,7 +16,7 @@ class Dropdown(Widget):
16
16
 
17
17
  super().__init__(name, value)
18
18
 
19
- self.choices = None
19
+ self.choices = []
20
20
 
21
21
  @property
22
22
  def schema_definition(self) -> dict:
@@ -22,7 +22,7 @@ class Text(Widget):
22
22
  self.text_wrap_length = None
23
23
  self.max_length = None
24
24
  self.comb = None
25
- self.character_paddings = None
25
+ self.character_paddings = []
26
26
  self.text_lines = None
27
27
  self.text_line_x_coordinates = None
28
28
  self.preview = False
PyPDFForm/patterns.py CHANGED
@@ -4,9 +4,9 @@
4
4
  from pypdf.generic import (DictionaryObject, NameObject, NumberObject,
5
5
  TextStringObject)
6
6
 
7
- from .constants import (AP, AS, CA, DA, FT, IMAGE_FIELD_IDENTIFIER, JS, MK,
7
+ from .constants import (AP, AS, CA, DA, DV, FT, IMAGE_FIELD_IDENTIFIER, JS, MK,
8
8
  READ_ONLY, A, Btn, Ch, Ff, N, Off, Opt, Parent, Q, Sig,
9
- Subtype, T, Tx, V, Widget, Yes)
9
+ T, Tx, V, Yes)
10
10
  from .middleware.checkbox import Checkbox
11
11
  from .middleware.dropdown import Dropdown
12
12
  from .middleware.image import Image
@@ -49,7 +49,7 @@ WIDGET_TYPE_PATTERNS = [
49
49
  (
50
50
  (
51
51
  {Parent: {FT: Btn}},
52
- {Parent: {Subtype: Widget}},
52
+ {Parent: {DV: (Yes, Off)}},
53
53
  {AS: (Yes, Off)},
54
54
  ),
55
55
  Checkbox,
PyPDFForm/template.py CHANGED
@@ -118,7 +118,7 @@ def update_text_field_attributes(
118
118
  ) -> None:
119
119
  """Auto updates text fields' attributes."""
120
120
 
121
- for _, _widgets in get_widgets_by_page(template_stream).items():
121
+ for _widgets in get_widgets_by_page(template_stream).values():
122
122
  for _widget in _widgets:
123
123
  key = get_widget_key(_widget)
124
124
 
@@ -155,11 +155,11 @@ def update_text_field_attributes(
155
155
  def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
156
156
  """Iterates through a PDF and returns all widgets found grouped by page."""
157
157
 
158
- pdf = PdfReader(stream_to_io(pdf))
158
+ pdf_file = PdfReader(stream_to_io(pdf))
159
159
 
160
160
  result = {}
161
161
 
162
- for i, page in enumerate(pdf.pages):
162
+ for i, page in enumerate(pdf_file.pages):
163
163
  widgets = page.annotations
164
164
  result[i + 1] = []
165
165
  if widgets:
@@ -177,7 +177,7 @@ def get_widgets_by_page(pdf: bytes) -> Dict[int, List[dict]]:
177
177
  return result
178
178
 
179
179
 
180
- def get_widget_key(widget: dict) -> Union[str, None]:
180
+ def get_widget_key(widget: dict) -> Union[str, list, None]:
181
181
  """Finds a PDF widget's annotated key by pattern matching."""
182
182
 
183
183
  result = None
@@ -189,7 +189,7 @@ def get_widget_key(widget: dict) -> Union[str, None]:
189
189
  return result
190
190
 
191
191
 
192
- def get_widget_alignment(widget: dict) -> Union[str, None]:
192
+ def get_widget_alignment(widget: dict) -> Union[str, list, None]:
193
193
  """Finds a PDF widget's alignment by pattern matching."""
194
194
 
195
195
  result = None
@@ -249,7 +249,7 @@ def is_text_multiline(widget: dict) -> bool:
249
249
  return check_field_flag_bit(widget, MULTILINE)
250
250
 
251
251
 
252
- def get_dropdown_choices(widget: dict) -> Union[Tuple[str], None]:
252
+ def get_dropdown_choices(widget: dict) -> Union[Tuple[str, ...], None]:
253
253
  """Returns string options of a dropdown field."""
254
254
 
255
255
  result = None
PyPDFForm/utils.py CHANGED
@@ -62,10 +62,10 @@ def preview_widget_to_draw(widget: WIDGET_TYPES) -> Text:
62
62
  def remove_all_widgets(pdf: bytes) -> bytes:
63
63
  """Removes all widgets from a PDF form."""
64
64
 
65
- pdf = PdfReader(stream_to_io(pdf))
65
+ pdf_file = PdfReader(stream_to_io(pdf))
66
66
  result_stream = BytesIO()
67
67
  writer = PdfWriter()
68
- for page in pdf.pages:
68
+ for page in pdf_file.pages:
69
69
  if page.annotations:
70
70
  page.annotations.clear()
71
71
  writer.add_page(page)
@@ -78,10 +78,10 @@ def remove_all_widgets(pdf: bytes) -> bytes:
78
78
  def get_page_streams(pdf: bytes) -> List[bytes]:
79
79
  """Returns a list of streams where each is a page of the input PDF."""
80
80
 
81
- pdf = PdfReader(stream_to_io(pdf))
81
+ pdf_file = PdfReader(stream_to_io(pdf))
82
82
  result = []
83
83
 
84
- for page in pdf.pages:
84
+ for page in pdf_file.pages:
85
85
  writer = PdfWriter()
86
86
  writer.add_page(page)
87
87
  with BytesIO() as f:
@@ -96,13 +96,13 @@ def merge_two_pdfs(pdf: bytes, other: bytes) -> bytes:
96
96
  """Merges two PDFs into one PDF."""
97
97
 
98
98
  output = PdfWriter()
99
- pdf = PdfReader(stream_to_io(pdf))
100
- other = PdfReader(stream_to_io(other))
99
+ pdf_file = PdfReader(stream_to_io(pdf))
100
+ other_file = PdfReader(stream_to_io(other))
101
101
  result = BytesIO()
102
102
 
103
- for page in pdf.pages:
103
+ for page in pdf_file.pages:
104
104
  output.add_page(page)
105
- for page in other.pages:
105
+ for page in other_file.pages:
106
106
  output.add_page(page)
107
107
 
108
108
  output.write(result)
PyPDFForm/watermark.py CHANGED
@@ -165,12 +165,9 @@ def create_watermarks_and_draw(
165
165
  watermark = buff.read()
166
166
  buff.close()
167
167
 
168
- results = []
169
-
170
- for i in range(len(pdf_file.pages)):
171
- results.append(watermark if i == page_number - 1 else b"")
172
-
173
- return results
168
+ return [
169
+ watermark if i == page_number - 1 else b"" for i in range(len(pdf_file.pages))
170
+ ]
174
171
 
175
172
 
176
173
  def merge_watermarks_with_pdf(
@@ -180,10 +177,10 @@ def merge_watermarks_with_pdf(
180
177
  """Merges watermarks with PDF."""
181
178
 
182
179
  result = BytesIO()
183
- pdf = PdfReader(stream_to_io(pdf))
180
+ pdf_file = PdfReader(stream_to_io(pdf))
184
181
  output = PdfWriter()
185
182
 
186
- for i, page in enumerate(pdf.pages):
183
+ for i, page in enumerate(pdf_file.pages):
187
184
  if watermarks[i]:
188
185
  watermark = PdfReader(stream_to_io(watermarks[i]))
189
186
  if watermark.pages:
PyPDFForm/widgets/base.py CHANGED
@@ -29,6 +29,7 @@ class Widget:
29
29
  ) -> None:
30
30
  """Sets acro form parameters."""
31
31
 
32
+ super().__init__()
32
33
  self.page_number = page_number
33
34
  self.acro_form_params = {
34
35
  "name": name,
@@ -71,8 +72,7 @@ class Widget:
71
72
  canvas.save()
72
73
  watermark.seek(0)
73
74
 
74
- result = []
75
- for i in range(page_count):
76
- result.append(watermark.read() if i == self.page_number - 1 else b"")
77
-
78
- return result
75
+ return [
76
+ watermark.read() if i == self.page_number - 1 else b""
77
+ for i in range(page_count)
78
+ ]
PyPDFForm/wrapper.py CHANGED
@@ -36,6 +36,7 @@ class FormWrapper:
36
36
  ) -> None:
37
37
  """Constructs all attributes for the object."""
38
38
 
39
+ super().__init__()
39
40
  self.stream = fp_or_f_obj_or_stream_to_stream(template)
40
41
 
41
42
  def read(self) -> bytes:
@@ -292,15 +293,13 @@ class PdfWrapper(FormWrapper):
292
293
  def schema(self) -> dict:
293
294
  """Generates a json schema for the PDF form template."""
294
295
 
295
- result = {
296
+ return {
296
297
  "type": "object",
297
298
  "properties": {
298
299
  key: value.schema_definition for key, value in self.widgets.items()
299
300
  },
300
301
  }
301
302
 
302
- return result
303
-
304
303
  @classmethod
305
304
  def register_font(
306
305
  cls, font_name: str, ttf_file: Union[bytes, str, BinaryIO]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPDFForm
3
- Version: 1.4.29
3
+ Version: 1.4.31
4
4
  Summary: The Python library for PDF forms.
5
5
  Home-page: https://github.com/chinapandaman/PyPDFForm
6
6
  Author: Jinge Li
@@ -0,0 +1,30 @@
1
+ PyPDFForm/__init__.py,sha256=pRovsD1TN9FVIkHD1qURZWnJ9SMefn8yY8jivZI5Tzs,179
2
+ PyPDFForm/adapter.py,sha256=WFP-r8FLeKa-D9mFO9AphOcuXgyeAI1Ak0d-YsqxsK4,861
3
+ PyPDFForm/constants.py,sha256=FMsdOvnYpchEfki3gf_Y2Wj1SThUxMzsPbOx12_S1GA,1738
4
+ PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
5
+ PyPDFForm/filler.py,sha256=pgMA7EC8axKUganmbk7X1uDdsb4OQQFoiI85td3pOO4,7486
6
+ PyPDFForm/font.py,sha256=TbFLY4G72d7cQ3VG2g4HaYKROzQPQUmh6-8ynN6hzXY,5713
7
+ PyPDFForm/image.py,sha256=0GV8PFgY5oLJFHmhPD1fG-_5SBEO7jVLLtxCc_Uodfo,1143
8
+ PyPDFForm/patterns.py,sha256=p33mDZKxQN2h8GgVnZGXNolWPzofky1llIpstjnL3eI,4318
9
+ PyPDFForm/template.py,sha256=a9rDzhHHfnYFo8cDnHnRE9UriUykXvrsyFKVGq9DYd0,13166
10
+ PyPDFForm/utils.py,sha256=9omR-oT3OdZqioxpiGqA9_P0GSFC6mg4Y1xrLvWOzkk,4309
11
+ PyPDFForm/watermark.py,sha256=L4LfzjjyJ6TDq9ad2dbtQYheBOic1_oZ7smhFFekNog,4725
12
+ PyPDFForm/wrapper.py,sha256=Rrb7PhbAWEWOwOX3Z5m-TEfTZfCnEY4AsWg7ashPe7c,9498
13
+ PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ PyPDFForm/middleware/base.py,sha256=p-3XsZJ6d7ai2JFLF7LisMWi9yzM3pN7CsFECxtEoI0,751
15
+ PyPDFForm/middleware/checkbox.py,sha256=3-9CMhhtyO9U6lLXDciW-59ng8uS4m6_clPB02mzV9c,1317
16
+ PyPDFForm/middleware/dropdown.py,sha256=On4bn8U9NSzDqytLEQuP5nEGTanJUm_DjtykYcJpyrI,672
17
+ PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
18
+ PyPDFForm/middleware/radio.py,sha256=ehaJoehEzZqxDVb5A6fJkYludeBmtV2Z5GZUPPfUWng,700
19
+ PyPDFForm/middleware/signature.py,sha256=m7tNvGZ7fQ0yuVKzSlLbNQ2IILo1GDnjzMDzMnYCKVM,1104
20
+ PyPDFForm/middleware/text.py,sha256=LNY_9Y2tq3uQEneKoL4vgrJtFTva0KSYzuuzDb5METM,1055
21
+ PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ PyPDFForm/widgets/base.py,sha256=mb8pKLu9d80pr-175T8f0FI1kWo2IOJ5am2_zRQKUl0,2075
23
+ PyPDFForm/widgets/checkbox.py,sha256=MGB6NGI-XMBz4j2erykgYOCd1pswvthuQ6UFowQOd4o,503
24
+ PyPDFForm/widgets/dropdown.py,sha256=2_R5xcLUWAL0G4raVgWWtE7TJdiWJITay-Gtl8YI2QI,705
25
+ PyPDFForm/widgets/text.py,sha256=x8EglZLYoI9osN9wORLRYoR7lebrpj-wx38QiRH7H1A,629
26
+ PyPDFForm-1.4.31.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
+ PyPDFForm-1.4.31.dist-info/METADATA,sha256=gnvLbIDdwFs1FaYpgGx2rgjTMEA1KeFHngG72BH-CtU,4151
28
+ PyPDFForm-1.4.31.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
29
+ PyPDFForm-1.4.31.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
+ PyPDFForm-1.4.31.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.1)
2
+ Generator: setuptools (70.3.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,30 +0,0 @@
1
- PyPDFForm/__init__.py,sha256=7PqqRfPhC05fsbxMhlPBXIs5vnUxIuZeSrivp55uw94,138
2
- PyPDFForm/adapter.py,sha256=OgAIwcmukpBqHFBLymd3I7wA7wIdipRqgURZA2Y0Hgo,885
3
- PyPDFForm/constants.py,sha256=Y-WINNe5GoOPfBFQroWuzzLELhAl-Fj_d7_3b1QodW0,1767
4
- PyPDFForm/coordinate.py,sha256=V_ZZQ1pXtVPAyfMJCX7fKoEimK7XwX6bU3VQ0nKOhQA,7314
5
- PyPDFForm/filler.py,sha256=pgMA7EC8axKUganmbk7X1uDdsb4OQQFoiI85td3pOO4,7486
6
- PyPDFForm/font.py,sha256=DCaKN6WIfNeMpP6ud17q1FOVRQXqrdevLycIQ9kItXQ,5711
7
- PyPDFForm/image.py,sha256=0GV8PFgY5oLJFHmhPD1fG-_5SBEO7jVLLtxCc_Uodfo,1143
8
- PyPDFForm/patterns.py,sha256=Ylfe6s9UV2X7cRAFQjaGoEa4nVSpEn-MLrH7IROp_aY,4332
9
- PyPDFForm/template.py,sha256=u3QxYdsT8HhoUBlhmChYaTJeFWI-SSrhICtUYsTTrow,13141
10
- PyPDFForm/utils.py,sha256=gDeRDszZ5Q59RjZjJYnikS2pQ_hc78osQH2Oy1TuLsY,4269
11
- PyPDFForm/watermark.py,sha256=clYdRqCuWEE25IL-BUHnSo4HgLkHPSOl7FUJLhbAfGg,4755
12
- PyPDFForm/wrapper.py,sha256=nwmaBkcnd0wt53s9SHHWFCvSJX4J2f7MU3ktt3105WU,9496
13
- PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- PyPDFForm/middleware/base.py,sha256=TmoO8XpjFa5NerAumrAGm_kUt2eFP3DyyF-Vx0uXloM,724
15
- PyPDFForm/middleware/checkbox.py,sha256=Z92awlKjceMd_ryb9Fhrtyd4fLkU84Ii6fSum60rHcA,1305
16
- PyPDFForm/middleware/dropdown.py,sha256=BpRh2YPndhhaLY-s-3gqck64d5FoC719-ARgvfV3_N0,674
17
- PyPDFForm/middleware/image.py,sha256=xjPxRiGBWFEU3EQGGqJXY1iMX1kmr0jO8O9iVUC5rcc,177
18
- PyPDFForm/middleware/radio.py,sha256=ehaJoehEzZqxDVb5A6fJkYludeBmtV2Z5GZUPPfUWng,700
19
- PyPDFForm/middleware/signature.py,sha256=m7tNvGZ7fQ0yuVKzSlLbNQ2IILo1GDnjzMDzMnYCKVM,1104
20
- PyPDFForm/middleware/text.py,sha256=-ETNQoLvgu5cLkpIQtNYHtq75Ou3P7ezYur-E1yb9-k,1057
21
- PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- PyPDFForm/widgets/base.py,sha256=Stq-oQt-cfwQ6nilQ4NqpO5udFSKDNb1mAwryrWggZA,2076
23
- PyPDFForm/widgets/checkbox.py,sha256=MGB6NGI-XMBz4j2erykgYOCd1pswvthuQ6UFowQOd4o,503
24
- PyPDFForm/widgets/dropdown.py,sha256=2_R5xcLUWAL0G4raVgWWtE7TJdiWJITay-Gtl8YI2QI,705
25
- PyPDFForm/widgets/text.py,sha256=x8EglZLYoI9osN9wORLRYoR7lebrpj-wx38QiRH7H1A,629
26
- PyPDFForm-1.4.29.dist-info/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
27
- PyPDFForm-1.4.29.dist-info/METADATA,sha256=XpWnZIbenPQtjTIZKAovCTQP7HX0vobgn70b5kc_Tms,4151
28
- PyPDFForm-1.4.29.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
29
- PyPDFForm-1.4.29.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
30
- PyPDFForm-1.4.29.dist-info/RECORD,,