Currently I am using the PyPDF 2 and i also tried PyPDF 4 also as a dependency.
I have encountered some encrypted files and handled them as you normally would (in the following code):
import PyPDF2
import PyPDF4
pdfFileObj = open(r'path', 'rb')
# creating a pdf reader object (Working until here)
pdfReader = PyPDF4.PdfFileReader(pdfFileObj)
# printing number of pages in pdf file (From here its not working)
print(pdfReader.numPages)
# creating a page object
pageObj = pdfReader.getPage(1)
# extracting text from page
print(pageObj.extractText())
# closing the pdf file object
pdfFileObj.close()
This gives the error:
PdfReadError: File has not been decrypted
I could call the pdf file into pdfFileObj variable. But when it hits print PDF.getNumPages(), it still raises the error, "PyPDF2.utils.PdfReadError: File has not been decrypted".
How do I get rid of this error? I can open the PDF file just fine by double click (which default-opens with Adobe Reader).