[英]PyPDF2 error "PyCryptodome is required for AES algorithm"
I've got hundreds on PDFs I need to set password.我有数百个需要设置密码的 PDF。 I tried to use pyPDF2 to do that but I got an error: "DependencyError: PyCryptodome is required for AES algorithm".
我尝试使用 pyPDF2 来执行此操作,但出现错误:“DependencyError:AES 算法需要 PyCryptodome”。
I've tried to google any other module like pikepdf but I found only how to crack the password using it and not to actually set password.我试图用谷歌搜索任何其他模块,如 pikepdf,但我只发现如何使用它来破解密码,而不是实际设置密码。
Any ideas how to deal with it?任何想法如何处理它? I get an error on that line: " input_pdf = PdfFileReader(in_file) "
我在该行收到错误:“ input_pdf = PdfFileReader(in_file) ”
file = directory + '\\passwords.xlsx'
df = pd.read_excel(file)
df['PDF'] = df.iloc[:,[0]] + '.pdf'
df = df.to_dict('records')
for i in df:
filename = i['PDF']
password = i['Password']
with open(filename, "rb") as in_file:
input_pdf = PdfFileReader(in_file)
output_pdf = PdfFileWriter()
output_pdf.appendPagesFromReader(input_pdf)
output_pdf.encrypt(password)
with open(filename, "wb") as out_file:
output_pdf.write(out_file)
https://roytuts.com/how-to-encrypt-pdf-as-password-protected-file-in-python/ https://roytuts.com/how-to-encrypt-pdf-as-password-protected-file-in-python/
import PyPDF2
#pdf_in_file = open("simple.pdf",'rb')
pdf_in_file = open("gre_research_validity_data.pdf",'rb')
inputpdf = PyPDF2.PdfFileReader(pdf_in_file)
pages_no = inputpdf.numPages
output = PyPDF2.PdfFileWriter()
for i in range(pages_no):
inputpdf = PyPDF2.PdfFileReader(pdf_in_file)
output.addPage(inputpdf.getPage(i))
output.encrypt('password')
#with open("simple_password_protected.pdf", "wb") as outputStream:
with open("gre_research_validity_data_password_protected.pdf", "wb") as outputStream:
output.write(outputStream)
pdf_in_file.close()
solution for similar error message but during counting pages - https://dailydevsblog.com/troubleshoot/solved-not-able-to-find-number-of-pages-of-pdf-using-python-3-x-dependencyerror-pycryptodome-is-required-for-aes-algorithm-221411/类似错误消息的解决方案,但在计数页面期间 - https://dailydevsblog.com/troubleshoot/solved-not-able-to-find-number-of-pages-of-pdf-using-python-3-x-dependencyerror- pycryptodome-is-required-for-aes-algorithm-221411/
ORIGINAL CODE原始代码
! 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)
FIX使固定
! pip install pikepdf
from pikepdf import Pdf
pdf = Pdf.open('Media Downloaded Files/spk-10-3144-bro.pdf')
len(pdf.pages)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.