2
2
"""Contains helpers for filling a PDF form."""
3
3
4
4
from io import BytesIO
5
- from typing import Dict , cast , Union , Tuple
5
+ from typing import Dict , Tuple , Union , cast
6
6
7
7
from pypdf import PdfReader , PdfWriter
8
8
from pypdf .generic import DictionaryObject
30
30
31
31
32
32
def check_radio_handler (
33
- widget : dict ,
34
- middleware : Union [Checkbox , Radio ],
35
- radio_button_tracker : dict
36
- ) -> Tuple [
37
- Text , Union [float , int ], Union [float , int ], bool
38
- ]:
33
+ widget : dict , middleware : Union [Checkbox , Radio ], radio_button_tracker : dict
34
+ ) -> Tuple [Text , Union [float , int ], Union [float , int ], bool ]:
39
35
"""Handles draw parameters for checkbox and radio button widgets."""
40
36
41
37
font_size = (
42
- checkbox_radio_font_size (widget )
43
- if middleware .size is None
44
- else middleware .size
38
+ checkbox_radio_font_size (widget ) if middleware .size is None else middleware .size
45
39
)
46
40
to_draw = checkbox_radio_to_draw (middleware , font_size )
47
41
x , y = get_draw_checkbox_radio_coordinates (widget , to_draw )
@@ -59,9 +53,7 @@ def check_radio_handler(
59
53
60
54
61
55
def signature_image_handler (
62
- widget : dict ,
63
- middleware : Union [Signature , Image ],
64
- images_to_draw : list
56
+ widget : dict , middleware : Union [Signature , Image ], images_to_draw : list
65
57
) -> bool :
66
58
"""Handles draw parameters for signature and image widgets."""
67
59
@@ -70,9 +62,7 @@ def signature_image_handler(
70
62
if stream is not None :
71
63
any_image_to_draw = True
72
64
stream = any_image_to_jpg (stream )
73
- x , y , width , height = get_draw_image_coordinates_resolutions (
74
- widget
75
- )
65
+ x , y , width , height = get_draw_image_coordinates_resolutions (widget )
76
66
images_to_draw .append (
77
67
[
78
68
stream ,
@@ -87,16 +77,11 @@ def signature_image_handler(
87
77
88
78
89
79
def text_handler (
90
- widget : dict ,
91
- middleware : Text
92
- ) -> Tuple [
93
- Text , Union [float , int ], Union [float , int ], bool
94
- ]:
80
+ widget : dict , middleware : Text
81
+ ) -> Tuple [Text , Union [float , int ], Union [float , int ], bool ]:
95
82
"""Handles draw parameters for text field widgets."""
96
83
97
- middleware .text_line_x_coordinates = get_text_line_x_coordinates (
98
- widget , middleware
99
- )
84
+ middleware .text_line_x_coordinates = get_text_line_x_coordinates (widget , middleware )
100
85
x , y = get_draw_text_coordinates (widget , middleware )
101
86
to_draw = middleware
102
87
text_needs_to_be_drawn = True
@@ -147,7 +132,9 @@ def fill(
147
132
widget_dict , widgets [key ], images_to_draw [page ]
148
133
)
149
134
else :
150
- to_draw , x , y , text_needs_to_be_drawn = text_handler (widget_dict , widgets [key ])
135
+ to_draw , x , y , text_needs_to_be_drawn = text_handler (
136
+ widget_dict , widgets [key ]
137
+ )
151
138
152
139
if all (
153
140
[
0 commit comments