我正在对从url下载的文件执行数据验证。其中一个验证检查涉及检查PDF的页数。使用PyPDF2包和PdfFileReader模块,直到我遇到一个具有权限密码但没有打开密码的256位AES加密的PDF。我无法访问任何密码,因为这些文件来自制造商网站,所以我的结论是,目前我只需检查PDF是否加密,如果是的话,暂时跳过它,但不管我是否试图检索页面计数或检查PDF是否加密,我都会得到以下错误:
DependencyError: PyCryptodome is required for AES algorithm
此错误发生在第6行if语句中。
尽管已经安装了pycryptodome并导入了AES模块,但还是存在这种情况。另外,我正在使用木星笔记本。这是我的代码:
! pip install PyPDF2
! pip install pycryptodome
from PyPDF2 import PdfFileReader
from Crypto.Cipher import AES
if PdfFileReader('Media Downloaded Files/spk-10-3144 bro.pdf').isEncrypted:
print('This file is encrypted.')
else:
print(PdfFileReader('Media Downloaded Files/spk-10-3144-bro.pdf').numPages)
解决方案:
! pip install pikepdf
from pikepdf import Pdf
pdf = Pdf.open('Media Downloaded Files/spk-10-3144-bro.pdf')
len(pdf.pages)
发布于 2022-08-30 00:31:58
我在使用PyPDF3 (这是PyPDF2的叉子)时遇到了加密问题。我为皮克普夫解决了更换它的问题。它有更多的加密算法实现。试试看!
https://stackoverflow.com/questions/73533948
复制相似问题