View Single Post
Old 07-12-2020, 12:55 PM   #4
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,738
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
It's also relatively easy to check for password-protected files with the PyPDF2 Python library:

1. Install Python 3.x and the PyPDF2 library.
2. Save the following lines as a text file with a *.py extension.
(Make sure to copy it verbatim; in Python, indentations matter. Missing/extra spaces will cause the script to fail.)

Code:
#!/usr/bin/env python
import sys, os, glob
from PyPDF2 import PdfFileReader

def main():
    current_dir = os.path.dirname(os.path.abspath(__file__))
    pdf_files = glob.glob(os.path.join(current_dir,  '**', '*.pdf*'), recursive=True)
    for pdf_file in pdf_files:
        with open(pdf_file, 'rb') as fh:
            reader = PdfFileReader(fh)
            encrypted = False
            if reader.isEncrypted: encrypted = True
        if encrypted: os.rename(pdf_file, pdf_file + '.encrypted.pdf')

if __name__ == "__main__":
   sys.exit(main())
3. Copy the *.py file to a folder with *.pdf files in it and double-click it.

If the script worked, all password-protected files should have an *.encryped.pdf extension. If it doesn't, open a command prompt/terminal window, execute the file and post the error messages.
Doitsu is offline   Reply With Quote