Currently I am using the PyPDF 2 as a dependency.
I have encountered some encrypted files and handled them as you normally would (in the following code):
<
The following code could solve this problem:
import os
import PyPDF2
from PyPDF2 import PdfFileReader
fp = open(filename)
pdfFile = PdfFileReader(fp)
if pdfFile.isEncrypted:
try:
pdfFile.decrypt('')
print('File Decrypted (PyPDF2)')
except:
command = ("cp "+ filename +
" temp.pdf; qpdf --password='' --decrypt temp.pdf " + filename
+ "; rm temp.pdf")
os.system(command)
print('File Decrypted (qpdf)')
fp = open(filename)
pdfFile = PdfFileReader(fp)
else:
print('File Not Encrypted')