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.
- PyPDFForm/__init__.py +22 -6
- PyPDFForm/adapter.py +28 -26
- PyPDFForm/constants.py +29 -34
- PyPDFForm/coordinate.py +23 -399
- PyPDFForm/filler.py +79 -303
- PyPDFForm/font.py +166 -164
- PyPDFForm/hooks.py +256 -0
- PyPDFForm/image.py +72 -22
- PyPDFForm/middleware/base.py +54 -48
- PyPDFForm/middleware/checkbox.py +29 -56
- PyPDFForm/middleware/dropdown.py +41 -30
- PyPDFForm/middleware/image.py +10 -22
- PyPDFForm/middleware/radio.py +30 -31
- PyPDFForm/middleware/signature.py +32 -47
- PyPDFForm/middleware/text.py +59 -48
- PyPDFForm/patterns.py +61 -141
- PyPDFForm/template.py +80 -427
- PyPDFForm/utils.py +142 -128
- PyPDFForm/watermark.py +77 -208
- PyPDFForm/widgets/base.py +57 -76
- PyPDFForm/widgets/checkbox.py +18 -21
- PyPDFForm/widgets/dropdown.py +18 -25
- PyPDFForm/widgets/image.py +11 -9
- PyPDFForm/widgets/radio.py +25 -35
- PyPDFForm/widgets/signature.py +29 -40
- PyPDFForm/widgets/text.py +18 -17
- PyPDFForm/wrapper.py +373 -437
- {pypdfform-2.4.0.dist-info → pypdfform-3.0.0.dist-info}/METADATA +6 -7
- pypdfform-3.0.0.dist-info/RECORD +35 -0
- {pypdfform-2.4.0.dist-info → pypdfform-3.0.0.dist-info}/WHEEL +1 -1
- pypdfform-2.4.0.dist-info/RECORD +0 -34
- {pypdfform-2.4.0.dist-info → pypdfform-3.0.0.dist-info}/licenses/LICENSE +0 -0
- {pypdfform-2.4.0.dist-info → pypdfform-3.0.0.dist-info}/top_level.txt +0 -0
PyPDFForm/widgets/dropdown.py
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
"""
|
|
11
|
+
"""
|
|
12
|
+
Represents a dropdown widget in a PDF form.
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
NONE_DEFAULTS:
|
|
24
|
-
ACRO_FORM_FUNC:
|
|
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
|
-
"""
|
|
34
|
+
"""
|
|
35
|
+
Initializes a DropdownWidget object.
|
|
39
36
|
|
|
40
37
|
Args:
|
|
41
|
-
name:
|
|
42
|
-
page_number: Page number
|
|
43
|
-
x: X coordinate
|
|
44
|
-
y: Y coordinate
|
|
45
|
-
**kwargs: Additional
|
|
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
|
]
|
PyPDFForm/widgets/image.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""
|
|
3
|
-
This module
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
14
|
+
Represents an image widget in a PDF form.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
and
|
|
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
|
|
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"
|
PyPDFForm/widgets/radio.py
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
"""
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
"""
|
|
16
|
+
"""
|
|
17
|
+
Represents a radio button widget in a PDF form.
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
"""
|
|
38
|
+
"""
|
|
39
|
+
Initializes a RadioWidget object.
|
|
44
40
|
|
|
45
41
|
Args:
|
|
46
|
-
name:
|
|
47
|
-
page_number: Page number
|
|
48
|
-
x: List of X coordinates for each radio button.
|
|
49
|
-
y: List of Y coordinates for each radio button.
|
|
50
|
-
**kwargs: Additional
|
|
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
|
-
"""
|
|
52
|
+
"""
|
|
53
|
+
Performs canvas operations for the radio button widget.
|
|
63
54
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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:
|
|
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()
|
PyPDFForm/widgets/signature.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""
|
|
3
|
-
This module
|
|
4
|
-
signature fields in PDF
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
24
|
+
Represents a signature widget in a PDF form.
|
|
25
25
|
|
|
26
|
-
This class
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
|
66
|
-
x (float): The x
|
|
67
|
-
y (float): The y
|
|
68
|
-
|
|
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.
|
|
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
|
-
|
|
74
|
+
Generates watermarks for the signature widget.
|
|
87
75
|
|
|
88
|
-
This method
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
82
|
+
stream (bytes): The PDF stream.
|
|
95
83
|
|
|
96
84
|
Returns:
|
|
97
|
-
List[bytes]: A list of
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
"""
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
"""
|
|
11
|
+
"""
|
|
12
|
+
Represents a text widget in a PDF form.
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
+
ALLOWED_HOOK_PARAMS = ["alignment", "multiline", "comb", "font"]
|
|
40
41
|
NONE_DEFAULTS = ["max_length"]
|
|
41
42
|
ACRO_FORM_FUNC = "textfield"
|