PyPDFForm 3.2.0__py3-none-any.whl → 3.3.0__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
@@ -20,7 +20,7 @@ The library supports various PDF form features, including:
20
20
  PyPDFForm aims to simplify PDF form manipulation, making it accessible to developers of all skill levels.
21
21
  """
22
22
 
23
- __version__ = "3.2.0"
23
+ __version__ = "3.3.0"
24
24
 
25
25
  from .middleware.text import Text # exposing for setting global font attrs
26
26
  from .wrapper import PdfWrapper
PyPDFForm/constants.py CHANGED
@@ -95,6 +95,7 @@ XFA = "/XFA"
95
95
 
96
96
  # Field flag bits
97
97
  READ_ONLY = 1 << 0
98
+ REQUIRED = 1 << 1
98
99
  MULTILINE = 1 << 12
99
100
  COMB = 1 << 24
100
101
 
PyPDFForm/hooks.py CHANGED
@@ -22,7 +22,8 @@ from pypdf.generic import (ArrayObject, DictionaryObject, FloatObject,
22
22
  NameObject, NumberObject, TextStringObject)
23
23
 
24
24
  from .constants import (COMB, DA, FONT_COLOR_IDENTIFIER, FONT_SIZE_IDENTIFIER,
25
- MULTILINE, READ_ONLY, Annots, Ff, Opt, Parent, Q, Rect)
25
+ MULTILINE, READ_ONLY, REQUIRED, TU, Annots, Ff, Opt,
26
+ Parent, Q, Rect)
26
27
  from .template import get_widget_key
27
28
  from .utils import stream_to_io
28
29
 
@@ -329,3 +330,48 @@ def flatten_generic(annot: DictionaryObject, val: bool) -> None:
329
330
  else int(annot.get(NameObject(Ff), 0)) & ~READ_ONLY
330
331
  )
331
332
  )
333
+
334
+
335
+ def update_field_tooltip(annot: DictionaryObject, val: str) -> None:
336
+ """
337
+ Updates the tooltip (alternate field name) of a form field annotation.
338
+
339
+ This function sets the 'TU' entry in the annotation dictionary, which
340
+ provides a text string that can be used as a tooltip for the field.
341
+
342
+ Args:
343
+ annot (DictionaryObject): The annotation dictionary for the form field.
344
+ val (str): The new tooltip string for the field.
345
+ """
346
+ if val:
347
+ annot[NameObject(TU)] = TextStringObject(val)
348
+
349
+
350
+ def update_field_required(annot: DictionaryObject, val: bool) -> None:
351
+ """
352
+ Updates the 'Required' flag of a form field annotation.
353
+
354
+ This function modifies the Ff (flags) entry in the annotation dictionary
355
+ (or its parent if applicable) to set or unset the 'Required' flag,
356
+ making the field mandatory or optional.
357
+
358
+ Args:
359
+ annot (DictionaryObject): The annotation dictionary for the form field.
360
+ val (bool): True to set the field as required, False to make it optional.
361
+ """
362
+ if Parent in annot and Ff not in annot:
363
+ annot[NameObject(Parent)][NameObject(Ff)] = NumberObject(
364
+ (
365
+ int(annot.get(NameObject(Ff), 0)) | REQUIRED
366
+ if val
367
+ else int(annot.get(NameObject(Ff), 0)) & ~REQUIRED
368
+ )
369
+ )
370
+ else:
371
+ annot[NameObject(Ff)] = NumberObject(
372
+ (
373
+ int(annot.get(NameObject(Ff), 0)) | REQUIRED
374
+ if val
375
+ else int(annot.get(NameObject(Ff), 0)) & ~REQUIRED
376
+ )
377
+ )
@@ -23,6 +23,8 @@ class Widget:
23
23
 
24
24
  SET_ATTR_TRIGGER_HOOK_MAP = {
25
25
  "readonly": "flatten_generic",
26
+ "required": "update_field_required",
27
+ "tooltip": "update_field_tooltip",
26
28
  }
27
29
 
28
30
  def __init__(
@@ -41,7 +43,9 @@ class Widget:
41
43
  self._name = name
42
44
  self._value = value
43
45
  self.desc: str = None
46
+ self.tooltip: str = None # TODO: sync tooltip and desc
44
47
  self.readonly: bool = None
48
+ self.required: bool = None
45
49
  self.hooks_to_trigger: list = []
46
50
 
47
51
  def __setattr__(self, name: str, value: Any) -> None:
@@ -25,6 +25,7 @@ class CheckBoxWidget(Widget):
25
25
  """
26
26
 
27
27
  USER_PARAMS = [
28
+ ("tooltip", "tooltip"),
28
29
  ("button_style", "buttonStyle"),
29
30
  ("tick_color", "textColor"),
30
31
  ("bg_color", "fillColor"),
@@ -32,5 +33,5 @@ class CheckBoxWidget(Widget):
32
33
  ("border_width", "borderWidth"),
33
34
  ]
34
35
  COLOR_PARAMS = ["tick_color", "bg_color", "border_color"]
35
- ALLOWED_HOOK_PARAMS = ["size"]
36
+ ALLOWED_HOOK_PARAMS = ["required", "size"]
36
37
  ACRO_FORM_FUNC = "checkbox"
@@ -34,6 +34,8 @@ class SignatureWidget:
34
34
  Attributes:
35
35
  OPTIONAL_PARAMS (list): A list of tuples, where each tuple contains the
36
36
  parameter name and its default value.
37
+ ALLOWED_HOOK_PARAMS (list): A list of parameter names that can be
38
+ used as hooks to trigger dynamic modifications.
37
39
  BEDROCK_WIDGET_TO_COPY (str): The name of the bedrock widget to copy.
38
40
  """
39
41
 
@@ -41,6 +43,7 @@ class SignatureWidget:
41
43
  ("width", 160),
42
44
  ("height", 90),
43
45
  ]
46
+ ALLOWED_HOOK_PARAMS = ["required", "tooltip"]
44
47
  BEDROCK_WIDGET_TO_COPY = "signature"
45
48
 
46
49
  def __init__(
@@ -71,6 +74,9 @@ class SignatureWidget:
71
74
  self.optional_params = {
72
75
  each[0]: kwargs.get(each[0], each[1]) for each in self.OPTIONAL_PARAMS
73
76
  }
77
+ for each in self.ALLOWED_HOOK_PARAMS:
78
+ if each in kwargs:
79
+ self.hook_params.append((each, kwargs.get(each)))
74
80
 
75
81
  def watermarks(self, stream: bytes) -> List[bytes]:
76
82
  """
PyPDFForm/widgets/text.py CHANGED
@@ -27,6 +27,7 @@ class TextWidget(Widget):
27
27
  """
28
28
 
29
29
  USER_PARAMS = [
30
+ ("tooltip", "tooltip"),
30
31
  ("width", "width"),
31
32
  ("height", "height"),
32
33
  ("font_size", "fontSize"),
@@ -37,6 +38,6 @@ class TextWidget(Widget):
37
38
  ("max_length", "maxlen"),
38
39
  ]
39
40
  COLOR_PARAMS = ["font_color", "bg_color", "border_color"]
40
- ALLOWED_HOOK_PARAMS = ["alignment", "multiline", "comb", "font"]
41
+ ALLOWED_HOOK_PARAMS = ["required", "alignment", "multiline", "comb", "font"]
41
42
  NONE_DEFAULTS = ["max_length"]
42
43
  ACRO_FORM_FUNC = "textfield"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: PyPDFForm
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: The Python library for PDF forms.
5
5
  Author: Jinge Li
6
6
  License-Expression: MIT
@@ -1,10 +1,10 @@
1
- PyPDFForm/__init__.py,sha256=MdhapOSXGvZvnL2gmvBhLy8__hBxfCI3beVkrNljOcg,925
1
+ PyPDFForm/__init__.py,sha256=ToO1r5zbCDJutiMz36Y_5mpA35NPoRtwTAsABtKUGEQ,925
2
2
  PyPDFForm/adapter.py,sha256=LBxHth0qJFB6rdByRJbsn4x0dftCOAolKVutZeFZm9E,2634
3
- PyPDFForm/constants.py,sha256=GU0LcNbN-ttYQVVoFGQLysKByJYF4lKoMideU65z_wI,2523
3
+ PyPDFForm/constants.py,sha256=Y5l1qIZGPsSoMl55bOsXaHf3yAY36_b-8KRxTLxXGmk,2541
4
4
  PyPDFForm/coordinate.py,sha256=veYOlRyFKIvzLISYA_f-drNBiKOzFwr0EIFCaUAzGgo,4428
5
5
  PyPDFForm/filler.py,sha256=fqGIxT3FR3cWo3SMTDYud6Ocs9SZBmSpFv5yg1v19Wk,8450
6
6
  PyPDFForm/font.py,sha256=opZjAacsIRFcERXWegPXkOSpmnRrv4y_50yD0_BjWPM,10273
7
- PyPDFForm/hooks.py,sha256=lXw3nNxYmgRp_IYe3aEXPeGCQxO_l6ruFzjmSeqfvIc,12659
7
+ PyPDFForm/hooks.py,sha256=3ugnhnrB4nFsGL6fc1TtT5Nf_J2QOtM5ZQsm6WVpErY,14279
8
8
  PyPDFForm/image.py,sha256=P1P3Ejm8PVPQwpJFGAesjtwS5hxnVItrj75TE3WnFhM,4607
9
9
  PyPDFForm/patterns.py,sha256=HbTqzFllQ1cW3CqyNEfVh0qUMeFerbvOd0-HQnkifQQ,9765
10
10
  PyPDFForm/template.py,sha256=Jvx99HjLcEG8fZQeGSPZEFcITa4jauPSvenj3XgAf3c,11046
@@ -12,7 +12,7 @@ PyPDFForm/utils.py,sha256=JavhAO4HmYRdujlsPXcZWGXTf7wDXzj4uU1XGRFsAaA,13257
12
12
  PyPDFForm/watermark.py,sha256=BJ8NeZLKf-MuJ2XusHiALaQpoqE8j6hHGbWcNhpjxN0,11299
13
13
  PyPDFForm/wrapper.py,sha256=KTFou6cXrHtLHVKwngoIr4Pwu4vOfjXY0cWRNNDlW0U,28866
14
14
  PyPDFForm/middleware/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- PyPDFForm/middleware/base.py,sha256=zBO9YP01dAEfFKoHKDg10XcpXEuYdFd-pb5wSFmJJj0,3091
15
+ PyPDFForm/middleware/base.py,sha256=ZmJFh3nSxj6PFjqBqsLih0pXKtcm1o-ctJVWn0v6bbI,3278
16
16
  PyPDFForm/middleware/checkbox.py,sha256=OCSZEFD8wQG_Y9qO7Os6VXTaxJCpkRYTxI4wDgG0GZc,1870
17
17
  PyPDFForm/middleware/dropdown.py,sha256=pfiMuAOr3ze7eboCB55UKaSR89oLNhvHGvNmDGWHVS0,3855
18
18
  PyPDFForm/middleware/image.py,sha256=eKM7anU56jbaECnK6rq0jGsBRY3HW_fM86fgA3hq7xA,585
@@ -22,14 +22,14 @@ PyPDFForm/middleware/text.py,sha256=GLKuYvG4BUtNvj-3NkDeIlV1jcouhn7gAqfm9TBWduQ,
22
22
  PyPDFForm/widgets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  PyPDFForm/widgets/base.py,sha256=vudfjwlybj82pxQhy6K8Qds9osFqn219Ze3yMs8QQuU,5786
24
24
  PyPDFForm/widgets/bedrock.py,sha256=j6beU04kaQzpAIFZHI5VJLaDT5RVAAa6LzkU1luJpN8,137660
25
- PyPDFForm/widgets/checkbox.py,sha256=s4a0a1pAemQyrz3SpZHzIPoVLvJZAV72KEfxKp15dyk,1281
25
+ PyPDFForm/widgets/checkbox.py,sha256=5Cg07d3SmRehkSiROtkK2vl0WKITxmv9BAKVnem8keM,1325
26
26
  PyPDFForm/widgets/dropdown.py,sha256=6zZwt6eU9Hgwl-57QfyT3G6c37FkQTJ-XSsXGluWevs,1459
27
27
  PyPDFForm/widgets/image.py,sha256=aSD-3MEZFIRL7HYVuO6Os8irfSUOLHA_rHGkqcEIPPA,855
28
28
  PyPDFForm/widgets/radio.py,sha256=oFw8Um4g414UH93QJv6dZHRxpq0yuYog09B2W3eE8wo,2612
29
- PyPDFForm/widgets/signature.py,sha256=vk9w9YmUpABvRhRcvllXw_Wr2SvKyCXDVQEFsR77ugM,4820
30
- PyPDFForm/widgets/text.py,sha256=gtheE6_w0vQPRJJ9oj_l9FaMDEGnPtvVR6_axsrmxKI,1540
31
- pypdfform-3.2.0.dist-info/licenses/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
32
- pypdfform-3.2.0.dist-info/METADATA,sha256=qjn9PkGilefmwJ0MocWv3DI8hvEDnJjh6buHCWzVpqA,4538
33
- pypdfform-3.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- pypdfform-3.2.0.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
35
- pypdfform-3.2.0.dist-info/RECORD,,
29
+ PyPDFForm/widgets/signature.py,sha256=L4Et6pxtrEh7U-lnnLZrnvb_dKwGNpI6TZ11HCD0lvY,5147
30
+ PyPDFForm/widgets/text.py,sha256=GjPwajoP20dZMlJGhJrQtwOa4VHGInjYkjUYmLwtRWs,1584
31
+ pypdfform-3.3.0.dist-info/licenses/LICENSE,sha256=43awmYkI6opyTpg19me731iO1WfXZwViqb67oWtCsFY,1065
32
+ pypdfform-3.3.0.dist-info/METADATA,sha256=K7q2yHg1rUw5hwO4gnmgNB8fR-UjPWce-z-0YY7gbWU,4538
33
+ pypdfform-3.3.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
+ pypdfform-3.3.0.dist-info/top_level.txt,sha256=GQQKuWqPUjT9YZqwK95NlAQzxjwoQrsxQ8ureM8lWOY,10
35
+ pypdfform-3.3.0.dist-info/RECORD,,