Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyPDF2 error "PyCryptodome is required for AES algorithm"

I've got hundreds on PDFs I need to set password. I tried to use pyPDF2 to do that but I got an error: "DependencyError: PyCryptodome is required for AES algorithm".

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.

Any ideas how to deal with it? I get an error on that line: "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)
like image 498
rammbb Avatar asked Feb 20 '26 04:02

rammbb


1 Answers

I had the same problem.

You just need to install PyCryptodome package.

For example:

pip install pycryptodome==3.15.0
like image 200
Anton Belsky Avatar answered Feb 21 '26 16:02

Anton Belsky