PyPDF2.utils.PdfReadError: File has not been decrypted

PyPDF2.utils.PdfReadError: File has not been decrypted

我一直在学习Python PyPDF2,这是geeksforgeeks.org/

上的代码
# importing required modules
import PyPDF2

# creating a pdf file object
pdfFileObj = open('English.pdf', 'rb')

# creating a pdf reader object
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)

# printing number of pages in pdf file
print(pdfReader.numPages)

# creating a page object
pageObj = pdfReader.getPage(0)

# extracting text from page
print(pageObj.extractText())

# closing the pdf file object
pdfFileObj.close()

在运行这个程序之后,弹出这个错误:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python38-32\lib\site-packages\PyPDF2\pdf.py", line 1147, in getNumPages
  self.decrypt('')
File "C:\Program Files (x86)\Python38-32\lib\site-packages\PyPDF2\pdf.py", line 1987, in decrypt  
  return self._decrypt(password)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\PyPDF2\pdf.py", line 1996, in _decrypt 
  raise NotImplementedError("only algorithm code 1 and 2 are supported")
NotImplementedError: only algorithm code 1 and 2 are supported

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 11, in <module>
  print(pdfReader.getNumPages())
File "C:\Program Files (x86)\Python38-32\lib\site-packages\PyPDF2\pdf.py", line 1150, in getNumPages
  raise utils.PdfReadError("File has not been decrypted")
PyPDF2.utils.PdfReadError: File has not been decrypted

我尝试了不同的方法来解决这个问题,但这个错误仍然存​​在,你能在这里指导我吗?

PyPDF2 只支持非常旧的 PDF 文件。它不支持 Acrobat 6 中的格式。您需要将其转换为旧格式或查找不同的 PDF 库。

https://github.com/mstamy2/PyPDF2/issues/378