'Raise NotImplementedError("only algorithm code 1 and 2 are supported")
I have created a simple code to decrypt an encrypted PDF file and create a new decrypted PDF file. Python version 3.10.1
Find the code below
from PyPDF2 import PdfFileReader, PdfFileWriter
def decrypt(file, password):
pdf = PdfFileReader(file)
writer = PdfFileWriter() #Creating empty PDF file
pdf.decrypt(password)
for i in range (pdf.getNumPages()):
page = pdf.getPage(i)
writer.addPage(page)
with open('Decrypted_' + file, 'wb') as output_file:
writer.write(output_file)
#give file name with .pdf extension
decrypt('PDFFile0112.pdf', 'abcdefg1234')
I get the below error
Traceback (most recent call last):
File "E:\Code\decrypt.py", line 16, in <module>
decrypt('PDFFile0112.pdf', 'abcdefg1234')
File "E:\Code\decrypt.py", line 6, in decrypt
pdf.decrypt(password)
File "C:\Users\llp\AppData\Local\Programs\Python\Python310\lib\site-packages\PyPDF2\pdf.py", line 1987, in decrypt
return self._decrypt(password)
File "C:\Users\llp\AppData\Local\Programs\Python\Python310\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
The strange thing is that the same code has worked before many times but it is not working now. What needs to be fixed in the code?
Both the code and the encrypted PDF file are in E://Code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
