21
21
import pdfly .x2pdf
22
22
23
23
24
- def version_callback (value : bool ) -> None :
24
+ def version_callback (value : bool ):
25
25
import pypdf
26
26
27
27
if value :
@@ -43,7 +43,7 @@ def version_callback(value: bool) -> None:
43
43
def common (
44
44
ctx : typer .Context ,
45
45
version : bool = typer .Option (None , "--version" , callback = version_callback ),
46
- ) -> None :
46
+ ):
47
47
pass
48
48
49
49
@@ -54,13 +54,11 @@ def extract_images(
54
54
typer .Argument (
55
55
exists = True ,
56
56
file_okay = True ,
57
- dir_okay = False ,
58
- writable = False ,
59
57
readable = True ,
60
58
resolve_path = True ,
61
59
),
62
60
]
63
- ) -> None :
61
+ ):
64
62
pdfly .extract_images .main (pdf )
65
63
66
64
@@ -71,14 +69,12 @@ def up2(
71
69
typer .Argument (
72
70
exists = True ,
73
71
file_okay = True ,
74
- dir_okay = False ,
75
- writable = False ,
76
72
readable = True ,
77
73
resolve_path = True ,
78
74
),
79
75
],
80
76
out : Path ,
81
- ) -> None :
77
+ ):
82
78
pdfly .up2 .main (pdf , out )
83
79
84
80
@@ -89,8 +85,6 @@ def cat(
89
85
typer .Argument (
90
86
exists = True ,
91
87
file_okay = True ,
92
- dir_okay = False ,
93
- writable = False ,
94
88
readable = True ,
95
89
resolve_path = True ,
96
90
),
@@ -102,7 +96,7 @@ def cat(
102
96
verbose : bool = typer .Option (
103
97
False , help = "show page ranges as they are being read"
104
98
),
105
- ) -> None :
99
+ ):
106
100
pdfly .cat .main (filename , fn_pgrgs , output , verbose )
107
101
108
102
@@ -113,8 +107,6 @@ def rm(
113
107
typer .Argument (
114
108
exists = True ,
115
109
file_okay = True ,
116
- dir_okay = False ,
117
- writable = False ,
118
110
readable = True ,
119
111
resolve_path = True ,
120
112
),
@@ -126,7 +118,7 @@ def rm(
126
118
verbose : bool = typer .Option (
127
119
False , help = "show page ranges as they are being read"
128
120
),
129
- ) -> None :
121
+ ):
130
122
pdfly .rm .main (filename , fn_pgrgs , output , verbose )
131
123
132
124
@@ -137,8 +129,6 @@ def metadata(
137
129
typer .Argument (
138
130
exists = True ,
139
131
file_okay = True ,
140
- dir_okay = False ,
141
- writable = False ,
142
132
readable = True ,
143
133
resolve_path = True ,
144
134
),
@@ -150,7 +140,7 @@ def metadata(
150
140
help = "output format" ,
151
141
show_default = True ,
152
142
),
153
- ) -> None :
143
+ ):
154
144
pdfly .metadata .main (pdf , output )
155
145
156
146
@@ -161,8 +151,6 @@ def pagemeta(
161
151
typer .Argument (
162
152
exists = True ,
163
153
file_okay = True ,
164
- dir_okay = False ,
165
- writable = False ,
166
154
readable = True ,
167
155
resolve_path = True ,
168
156
),
@@ -175,7 +163,7 @@ def pagemeta(
175
163
help = "output format" ,
176
164
show_default = True ,
177
165
),
178
- ) -> None :
166
+ ):
179
167
pdfly .pagemeta .main (
180
168
pdf ,
181
169
page_index ,
@@ -190,19 +178,17 @@ def extract_text(
190
178
typer .Argument (
191
179
exists = True ,
192
180
file_okay = True ,
193
- dir_okay = False ,
194
- writable = False ,
195
181
readable = True ,
196
182
resolve_path = True ,
197
183
),
198
184
]
199
- ) -> None :
185
+ ):
200
186
"""Extract text from a PDF file."""
201
187
from pypdf import PdfReader
202
188
203
189
reader = PdfReader (str (pdf ))
204
190
for page in reader .pages :
205
- print (page .extract_text ())
191
+ typer . echo (page .extract_text ())
206
192
207
193
208
194
@entry_point .command (name = "compress" , help = pdfly .compress .__doc__ ) # type: ignore[misc]
@@ -212,8 +198,6 @@ def compress(
212
198
typer .Argument (
213
199
exists = True ,
214
200
file_okay = True ,
215
- dir_okay = False ,
216
- writable = False ,
217
201
readable = True ,
218
202
resolve_path = True ,
219
203
),
@@ -225,13 +209,21 @@ def compress(
225
209
writable = True ,
226
210
),
227
211
],
228
- ) -> None :
212
+ ):
229
213
pdfly .compress .main (pdf , output )
230
214
231
215
232
216
@entry_point .command (name = "update-offsets" , help = pdfly .update_offsets .__doc__ ) # type: ignore[misc]
233
217
def update_offsets (
234
- file_in : Path ,
218
+ file_in : Annotated [
219
+ Path ,
220
+ typer .Argument (
221
+ exists = True ,
222
+ file_okay = True ,
223
+ readable = True ,
224
+ resolve_path = True ,
225
+ ),
226
+ ],
235
227
file_out : Path ,
236
228
encoding : str = typer .Option (
237
229
"ISO-8859-1" ,
@@ -240,21 +232,32 @@ def update_offsets(
240
232
verbose : bool = typer .Option (
241
233
False , help = "Show progress while processing."
242
234
),
243
- ) -> None :
235
+ ):
244
236
pdfly .update_offsets .main (file_in , file_out , encoding , verbose )
245
237
246
238
247
239
@entry_point .command (name = "x2pdf" , help = pdfly .x2pdf .__doc__ ) # type: ignore[misc]
248
240
def x2pdf (
249
- x : List [Path ],
241
+ x : List [
242
+ Annotated [
243
+ Path ,
244
+ typer .Argument (
245
+ exists = True ,
246
+ file_okay = True ,
247
+ readable = True ,
248
+ resolve_path = True ,
249
+ ),
250
+ ]
251
+ ],
250
252
output : Annotated [
251
253
Path ,
252
254
typer .Option (
253
255
"-o" ,
254
256
"--output" ,
255
- exists = False ,
256
257
writable = True ,
257
258
),
258
259
],
259
- ) -> int :
260
- return pdfly .x2pdf .main (x , output )
260
+ ):
261
+ exit_code = pdfly .x2pdf .main (x , output )
262
+ if exit_code :
263
+ raise typer .Exit (code = exit_code )
0 commit comments