PyPDFForm 2.4.0__py3-none-any.whl → 3.0.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.

@@ -1,27 +1,23 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides dropdown widget creation functionality for PDF forms.
3
-
4
- This module contains the DropdownWidget class which handles creation of:
5
- - Interactive dropdown/combobox fields
6
- - Option list management
7
- - Visual styling inheritance from text fields
8
- - Form field integration
2
+ """
3
+ This module defines the DropdownWidget class, which is a subclass of the
4
+ TextWidget class. It represents a dropdown form field in a PDF document.
9
5
  """
10
6
 
11
7
  from .text import TextWidget
12
8
 
13
9
 
14
10
  class DropdownWidget(TextWidget):
15
- """Creates and configures PDF dropdown widgets.
11
+ """
12
+ Represents a dropdown widget in a PDF form.
16
13
 
17
- Extends TextWidget to support dropdown/combobox functionality including:
18
- - Option list management
19
- - Initial value selection
20
- - All inherited text field styling options
14
+ Inherits from the base TextWidget class and adds specific parameters for
15
+ dropdown styling, such as options.
21
16
 
22
- Class Attributes:
23
- NONE_DEFAULTS: Empty list - dropdowns require options
24
- ACRO_FORM_FUNC: Uses underlying text field creation function
17
+ Attributes:
18
+ NONE_DEFAULTS (list): A list of parameters that default to None.
19
+ ACRO_FORM_FUNC (str): The name of the AcroForm function to use for
20
+ creating the dropdown.
25
21
  """
26
22
 
27
23
  NONE_DEFAULTS = []
@@ -35,19 +31,16 @@ class DropdownWidget(TextWidget):
35
31
  y: float,
36
32
  **kwargs,
37
33
  ) -> None:
38
- """Initializes a new dropdown widget with options.
34
+ """
35
+ Initializes a DropdownWidget object.
39
36
 
40
37
  Args:
41
- name: Field name/key for the dropdown
42
- page_number: Page number to place widget on (1-based)
43
- x: X coordinate for widget position
44
- y: Y coordinate for widget position
45
- **kwargs: Additional widget parameters including:
46
- width/height: Field dimensions
47
- font/font_size: Text styling
48
- options: List of dropdown choices
38
+ name (str): Name of the widget.
39
+ page_number (int): Page number of the widget.
40
+ x (float): X coordinate of the widget.
41
+ y (float): Y coordinate of the widget.
42
+ **kwargs: Additional keyword arguments.
49
43
  """
50
-
51
44
  self.USER_PARAMS = super().USER_PARAMS[:-1] + [
52
45
  ("options", "options"),
53
46
  ]
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """
3
- This module provides the ImageWidget class for creating and customizing
4
- image fields in PDF forms. It extends SignatureWidget to enable placement
5
- of image widgets on specified pages and coordinates, using an image field
6
- template instead of a signature field template.
3
+ This module defines the ImageWidget class, which is a subclass of the
4
+ SignatureWidget class. It represents an image field in a PDF document.
5
+ The ImageWidget leverages the SignatureWidget's functionality to handle
6
+ image insertion into PDF forms.
7
7
  """
8
8
 
9
9
  from .signature import SignatureWidget
@@ -11,14 +11,16 @@ from .signature import SignatureWidget
11
11
 
12
12
  class ImageWidget(SignatureWidget):
13
13
  """
14
- A widget for adding an image field to a PDF form.
14
+ Represents an image widget in a PDF form.
15
15
 
16
- Inherits from SignatureWidget, but uses an image widget template
17
- instead of a signature field template. All initialization parameters
18
- and methods are inherited from SignatureWidget.
16
+ This class inherits from the SignatureWidget and is specifically designed
17
+ for handling image fields in PDF forms. It reuses the signature widget's
18
+ infrastructure for positioning and rendering, but instead of capturing
19
+ a signature, it inserts a provided image.
19
20
 
20
21
  Attributes:
21
- BEDROCK_WIDGET_TO_COPY (str): The widget type to copy from the bedrock template ("image").
22
+ BEDROCK_WIDGET_TO_COPY (str): The name of the bedrock widget to copy,
23
+ set to "image".
22
24
  """
23
25
 
24
26
  BEDROCK_WIDGET_TO_COPY = "image"
@@ -1,14 +1,8 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides radio button widget creation functionality for PDF forms.
3
-
4
- This module contains the RadioWidget class which handles creation of:
5
- - Interactive radio button fields for mutually exclusive selections
6
- - Custom button styles and color styling
7
- - Size adjustments
8
- - PDF form field integration
9
-
10
- Supports all standard PDF radio button properties and integrates with both
11
- AcroForm and non-AcroForm PDF documents.
2
+ """
3
+ This module defines the RadioWidget class, which is a subclass of the
4
+ CheckBoxWidget class. It represents a radio button form field in a PDF
5
+ document.
12
6
  """
13
7
 
14
8
  from typing import List
@@ -19,15 +13,16 @@ from .checkbox import CheckBoxWidget
19
13
 
20
14
 
21
15
  class RadioWidget(CheckBoxWidget):
22
- """Creates and configures PDF radio button widgets.
16
+ """
17
+ Represents a radio button widget in a PDF form.
23
18
 
24
- Supports all standard radio button properties including:
25
- - Mutually exclusive selection handling
26
- - Button style customization and color styling
27
- - Size adjustments
28
- - PDF form field integration
19
+ This class inherits from the CheckBoxWidget and is designed for handling
20
+ radio button fields in PDF forms. Radio buttons allow the user to select
21
+ only one option from a predefined set of choices.
29
22
 
30
- Inherits from CheckBoxWidget, adding radio-specific parameters and logic.
23
+ Attributes:
24
+ ACRO_FORM_FUNC (str): The name of the AcroForm function to use for
25
+ creating the radio button, set to "radio".
31
26
  """
32
27
 
33
28
  ACRO_FORM_FUNC = "radio"
@@ -40,35 +35,30 @@ class RadioWidget(CheckBoxWidget):
40
35
  y: List[float],
41
36
  **kwargs,
42
37
  ) -> None:
43
- """Initializes a new radio button widget with options.
38
+ """
39
+ Initializes a RadioWidget object.
44
40
 
45
41
  Args:
46
- name: Field name/key for the radio group.
47
- page_number: Page number to place widget on (1-based).
48
- x: List of X coordinates for each radio button.
49
- y: List of Y coordinates for each radio button.
50
- **kwargs: Additional widget parameters including:
51
- width/height: Field dimensions.
52
- font/font_size: Text styling.
53
- options: List of radio button choices.
54
- shape: Button style (e.g., circle, check, cross, etc.).
55
- color: Button color and border styling.
42
+ name (str): Name of the widget.
43
+ page_number (int): Page number of the widget.
44
+ x (List[float]): List of X coordinates for each radio button.
45
+ y (List[float]): List of Y coordinates for each radio button.
46
+ **kwargs: Additional keyword arguments.
56
47
  """
57
-
58
48
  self.USER_PARAMS.append(("shape", "shape"))
59
49
  super().__init__(name, page_number, x, y, **kwargs)
60
50
 
61
51
  def canvas_operations(self, canvas: Canvas) -> None:
62
- """Draws all radio button options on the provided PDF canvas.
52
+ """
53
+ Performs canvas operations for the radio button widget.
63
54
 
64
- Iterates over each (x, y) coordinate pair for the radio button group,
65
- sets the value for each option, and calls the AcroForm radio function
66
- to render each button on the canvas.
55
+ This method iterates through the X and Y coordinates of each radio button
56
+ and draws it on the PDF canvas. It also sets the value of the radio button
57
+ based on its index in the list of coordinates.
67
58
 
68
59
  Args:
69
- canvas: The ReportLab Canvas object to draw the radio buttons on.
60
+ canvas (Canvas): Canvas object to operate on.
70
61
  """
71
-
72
62
  for i, x in enumerate(self.acro_form_params["x"]):
73
63
  y = self.acro_form_params["y"][i]
74
64
  new_acro_form_params = self.acro_form_params.copy()
@@ -1,9 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  """
3
- This module provides the SignatureWidget class for creating and customizing
4
- signature fields in PDF forms. It enables placement of signature widgets
5
- on specified pages and coordinates, and generates watermark overlays for
6
- PDF documents to visually represent signature fields.
3
+ This module defines the SignatureWidget class, which is responsible for
4
+ representing signature fields in a PDF form. It handles the creation and
5
+ rendering of signature widgets, as well as the integration of signatures
6
+ into the PDF document.
7
7
  """
8
8
 
9
9
  from io import BytesIO
@@ -21,26 +21,17 @@ from .bedrock import BEDROCK_PDF
21
21
 
22
22
  class SignatureWidget:
23
23
  """
24
- A widget for adding a digital signature field to a PDF form.
24
+ Represents a signature widget in a PDF form.
25
25
 
26
- This class allows you to specify the name, page number, position (x, y),
27
- and size (width, height) of a signature field to be placed on a PDF page.
28
- The widget is based on a bedrock template and can generate a watermark
29
- overlay for the specified page, updating the annotation's name and rectangle
30
- to match the provided parameters.
26
+ This class is responsible for handling the creation, rendering, and
27
+ integration of signature fields in a PDF document. It inherits from
28
+ the base Widget class and provides specific functionality for handling
29
+ signatures.
31
30
 
32
31
  Attributes:
33
- BEDROCK_WIDGET_TO_COPY (str): The widget type to copy from the bedrock template.
34
- name (str): The name of the signature field.
35
- page_number (int): The 1-based page number where the signature field will appear.
36
- x (float): The x-coordinate of the lower-left corner of the signature field.
37
- y (float): The y-coordinate of the lower-left corner of the signature field.
38
- optional_params (dict): Optional parameters for widget customization (e.g., width, height).
39
-
40
- Methods:
41
- watermarks(stream: bytes) -> List[bytes]:
42
- Generates a list of watermark overlays, with the signature field
43
- applied to the specified page.
32
+ OPTIONAL_PARAMS (list): A list of tuples, where each tuple contains the
33
+ parameter name and its default value.
34
+ BEDROCK_WIDGET_TO_COPY (str): The name of the bedrock widget to copy.
44
35
  """
45
36
 
46
37
  OPTIONAL_PARAMS = [
@@ -58,20 +49,17 @@ class SignatureWidget:
58
49
  **kwargs,
59
50
  ) -> None:
60
51
  """
61
- Initialize a SignatureWidget.
52
+ Initializes a SignatureWidget object.
62
53
 
63
54
  Args:
64
55
  name (str): The name of the signature widget.
65
- page_number (int): The page number where the widget will be placed (1-based).
66
- x (float): The x-coordinate of the widget's lower-left corner.
67
- y (float): The y-coordinate of the widget's lower-left corner.
68
- width (float, optional): The width of the widget. Defaults to 160 if not provided.
69
- height (float, optional): The height of the widget. Defaults to 90 if not provided.
70
- **kwargs: Additional optional parameters for widget customization.
56
+ page_number (int): The page number of the signature widget.
57
+ x (float): The x coordinate of the signature widget.
58
+ y (float): The y coordinate of the signature widget.
59
+ **kwargs: Additional keyword arguments.
71
60
  """
72
-
73
61
  super().__init__()
74
- self.non_acro_form_params = []
62
+ self.hook_params = []
75
63
 
76
64
  self.page_number = page_number
77
65
  self.name = name
@@ -83,22 +71,23 @@ class SignatureWidget:
83
71
 
84
72
  def watermarks(self, stream: bytes) -> List[bytes]:
85
73
  """
86
- Generate watermark overlays for the signature widget on the specified PDF page.
74
+ Generates watermarks for the signature widget.
87
75
 
88
- This method creates a list of watermark overlays for each page in the input PDF.
89
- Only the page corresponding to `page_number` contains the signature widget overlay,
90
- which is generated by copying and customizing a signature annotation from a bedrock
91
- template PDF. All other pages in the returned list are empty byte strings.
76
+ This method takes a PDF stream as input, reads a "bedrock" PDF, and
77
+ creates a new PDF with the signature widget added as a watermark on the
78
+ specified page. The signature's name and rectangle are then added to the
79
+ new PDF.
92
80
 
93
81
  Args:
94
- stream (bytes): The PDF file as a byte stream.
82
+ stream (bytes): The PDF stream.
95
83
 
96
84
  Returns:
97
- List[bytes]: A list of byte streams, one for each page in the input PDF.
98
- Only the page corresponding to `page_number` contains the
99
- signature widget overlay; other pages are empty byte strings.
85
+ List[bytes]: A list of watermarks for the signature widget. Each
86
+ element in the list represents a page in the PDF. If the current
87
+ page matches the signature's page number, the corresponding element
88
+ will contain the watermark data. Otherwise, the element will be an
89
+ empty byte string.
100
90
  """
101
-
102
91
  input_pdf = PdfReader(stream_to_io(stream))
103
92
  page_count = len(input_pdf.pages)
104
93
  pdf = PdfReader(stream_to_io(BEDROCK_PDF))
PyPDFForm/widgets/text.py CHANGED
@@ -1,33 +1,34 @@
1
1
  # -*- coding: utf-8 -*-
2
- """Provides text field widget creation functionality for PDF forms.
3
-
4
- This module contains the TextWidget class which handles creation of:
5
- - Standard text input fields
6
- - Multiline text fields
7
- - Font and color styling
8
- - Field size and length constraints
2
+ """
3
+ This module defines the TextWidget class, which is a subclass of the
4
+ Widget class. It represents a text field in a PDF document.
9
5
  """
10
6
 
11
7
  from .base import Widget
12
8
 
13
9
 
14
10
  class TextWidget(Widget):
15
- """Creates and configures PDF text field widgets.
11
+ """
12
+ Represents a text widget in a PDF form.
16
13
 
17
- Supports all standard text field properties including:
18
- - Font styling (family, size, color)
19
- - Background and border colors
20
- - Width/height dimensions
21
- - Maximum length constraints
22
- - Alignment and multiline options
14
+ This class inherits from the base Widget class and provides specific
15
+ parameters for text field styling, such as width, height, font size,
16
+ font color, background color, border color, border width, and maximum
17
+ length.
23
18
 
24
- Inherits from Widget base class adding text-specific parameters.
19
+ Attributes:
20
+ USER_PARAMS (list): A list of tuples, where each tuple contains the
21
+ user-facing parameter name and the corresponding AcroForm parameter name.
22
+ COLOR_PARAMS (list): A list of user-facing parameter names that represent colors.
23
+ ALLOWED_HOOK_PARAMS (list): A list of allowed hook parameters.
24
+ NONE_DEFAULTS (list): A list of parameters that default to None.
25
+ ACRO_FORM_FUNC (str): The name of the AcroForm function to use for
26
+ creating the text field.
25
27
  """
26
28
 
27
29
  USER_PARAMS = [
28
30
  ("width", "width"),
29
31
  ("height", "height"),
30
- ("font", "fontName"),
31
32
  ("font_size", "fontSize"),
32
33
  ("font_color", "textColor"),
33
34
  ("bg_color", "fillColor"),
@@ -36,6 +37,6 @@ class TextWidget(Widget):
36
37
  ("max_length", "maxlen"),
37
38
  ]
38
39
  COLOR_PARAMS = ["font_color", "bg_color", "border_color"]
39
- ALLOWED_NON_ACRO_FORM_PARAMS = ["alignment", "multiline"]
40
+ ALLOWED_HOOK_PARAMS = ["alignment", "multiline", "comb", "font"]
40
41
  NONE_DEFAULTS = ["max_length"]
41
42
  ACRO_FORM_FUNC = "textfield"