@@ -44,6 +44,7 @@ def convert_from_path(
44
44
jpegopt = None ,
45
45
thread_count = 1 ,
46
46
userpw = None ,
47
+ ownerpw = None ,
47
48
use_cropbox = False ,
48
49
strict = False ,
49
50
transparent = False ,
@@ -69,6 +70,7 @@ def convert_from_path(
69
70
jpegopt -> jpeg options `quality`, `progressive`, and `optimize` (only for jpeg format)
70
71
thread_count -> How many threads we are allowed to spawn for processing
71
72
userpw -> PDF's password
73
+ ownerpw -> PDF's owner password
72
74
use_cropbox -> Use cropbox instead of mediabox
73
75
strict -> When a Syntax Error is thrown, it will be raised as an Exception
74
76
transparent -> Output with a transparent background instead of a white one.
@@ -95,7 +97,7 @@ def convert_from_path(
95
97
if isinstance (poppler_path , pathlib .PurePath ):
96
98
poppler_path = poppler_path .as_posix ()
97
99
98
- page_count = pdfinfo_from_path (pdf_path , userpw , poppler_path = poppler_path )["Pages" ]
100
+ page_count = pdfinfo_from_path (pdf_path , userpw , ownerpw , poppler_path = poppler_path )["Pages" ]
99
101
100
102
# We start by getting the output format, the buffer processing function and if we need pdftocairo
101
103
parsed_fmt , final_extension , parse_buffer_func , use_pdfcairo_format = _parse_format (
@@ -169,6 +171,7 @@ def convert_from_path(
169
171
jpegopt ,
170
172
thread_output_file ,
171
173
userpw ,
174
+ ownerpw ,
172
175
use_cropbox ,
173
176
transparent ,
174
177
single_file ,
@@ -237,6 +240,7 @@ def convert_from_bytes(
237
240
jpegopt = None ,
238
241
thread_count = 1 ,
239
242
userpw = None ,
243
+ ownerpw = None ,
240
244
use_cropbox = False ,
241
245
strict = False ,
242
246
transparent = False ,
@@ -262,6 +266,7 @@ def convert_from_bytes(
262
266
jpegopt -> jpeg options `quality`, `progressive`, and `optimize` (only for jpeg format)
263
267
thread_count -> How many threads we are allowed to spawn for processing
264
268
userpw -> PDF's password
269
+ ownerpw -> PDF's owner password
265
270
use_cropbox -> Use cropbox instead of mediabox
266
271
strict -> When a Syntax Error is thrown, it will be raised as an Exception
267
272
transparent -> Output with a transparent background instead of a white one.
@@ -290,6 +295,7 @@ def convert_from_bytes(
290
295
jpegopt = jpegopt ,
291
296
thread_count = thread_count ,
292
297
userpw = userpw ,
298
+ ownerpw = ownerpw ,
293
299
use_cropbox = use_cropbox ,
294
300
strict = strict ,
295
301
transparent = transparent ,
@@ -317,6 +323,7 @@ def _build_command(
317
323
jpegopt ,
318
324
output_file ,
319
325
userpw ,
326
+ ownerpw ,
320
327
use_cropbox ,
321
328
transparent ,
322
329
single_file ,
@@ -354,6 +361,9 @@ def _build_command(
354
361
if userpw is not None :
355
362
args .extend (["-upw" , userpw ])
356
363
364
+ if ownerpw is not None :
365
+ args .extend (["-opw" , ownerpw ])
366
+
357
367
if grayscale :
358
368
args .append ("-gray" )
359
369
@@ -440,14 +450,17 @@ def _get_poppler_version(command, poppler_path=None, timeout=None):
440
450
441
451
442
452
def pdfinfo_from_path (
443
- pdf_path , userpw = None , poppler_path = None , rawdates = False , timeout = None
453
+ pdf_path , userpw = None , ownerpw = None , poppler_path = None , rawdates = False , timeout = None
444
454
):
445
455
try :
446
456
command = [_get_command_path ("pdfinfo" , poppler_path ), pdf_path ]
447
457
448
458
if userpw is not None :
449
459
command .extend (["-upw" , userpw ])
450
460
461
+ if ownerpw is not None :
462
+ command .extend (["-opw" , ownerpw ])
463
+
451
464
if rawdates :
452
465
command .extend (["-rawdates" ])
453
466
@@ -491,15 +504,15 @@ def pdfinfo_from_path(
491
504
492
505
493
506
def pdfinfo_from_bytes (
494
- pdf_file , userpw = None , poppler_path = None , rawdates = False , timeout = None
507
+ pdf_file , userpw = None , ownerpw = None , poppler_path = None , rawdates = False , timeout = None
495
508
):
496
509
fh , temp_filename = tempfile .mkstemp ()
497
510
try :
498
511
with open (temp_filename , "wb" ) as f :
499
512
f .write (pdf_file )
500
513
f .flush ()
501
- return pdfinfo_from_path (temp_filename , userpw = userpw , rawdates = rawdates ,
502
- poppler_path = poppler_path )
514
+ return pdfinfo_from_path (temp_filename , userpw = userpw , ownerpw = ownerpw ,
515
+ rawdates = rawdates , poppler_path = poppler_path )
503
516
finally :
504
517
os .close (fh )
505
518
os .remove (temp_filename )
0 commit comments