Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan for secured pdf documents

Tags:

python

pypdf

I've currently run into the need to find which pdfs within a directory are "Secured Documents". All of the pdfs should be unsecured, and convertible via xpdf, however, this is not the case. How could I scan through all the pdfs in a directory to find out whether or not they are secured?


1 Answers

pypdf supports decrypting PDFs. Its PdfReader class has an is_encrypted attribute.

import pypdf
if pypdf.PdfReader("file_name.pdf").is_encrypted:
    print("Rut ro, it's encrypted.")
    # skip file? Write to a log?
else:
    print("We're clear.")
    # Do stuff with the file.
like image 176
nmichaels Avatar answered Oct 28 '25 17:10

nmichaels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!