Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

only algorithm code 1 and 2 are supported

Tags:

python

pypdf2

I would like to read the pdf file. This is a book.pdf with a password (256 bit AES encryption). I know a password. I am using Jupyter Notebook.

I get an error:

import PyPDF2
reader = PyPDF2.PdfFileReader('book.pdf')
reader.decrypt('333')
reader.getPage(0)


---------------------------------------------------------------------------
 NotImplementedError                       Traceback (most recent call last)
 <ipython-input-12-7dd54b6a760a> in <module>()
  1 import PyPDF2
  2 reader = PyPDF2.PdfFileReader('book.pdf')
  ----> 3 reader.decrypt('333')
  4 reader.getPage(0)

 c:\users\a\programs\python\python36-32\lib\site-packages\PyPDF2\pdf.py in 
 decrypt(self, password)
 1985         self._override_encryption = True
 1986         try:
 -> 1987             return self._decrypt(password)
 1988         finally:
 1989             self._override_encryption = False

 c:\users\a\python\python36-32\lib\site-packages\PyPDF2\pdf.py in 
_decrypt(self, password)
1994             raise NotImplementedError("only Standard PDF encryption 
handler is available")
1995         if not (encrypt['/V'] in (1, 2)):
-> 1996             raise NotImplementedError("only algorithm code 1 and 2 
are supported")
1997         user_password, key = self._authenticateUserPassword(password)
1998         if user_password:

NotImplementedError: only algorithm code 1 and 2 are supported
like image 990
batmanforever Avatar asked Jun 07 '18 23:06

batmanforever


2 Answers

Recently, I also faced the same issue. I am not sure why the error occurs, but here is a way to mitigate it, using a different module than PyPDF2 :

import pikepdf
pdf = pikepdf.open('book.pdf',password='333')
pdf.save('book_without_pass.pdf')

The above code save the encrypted pdf book.pdf with the password, '333' to book_without_pass.pdf

like image 102
Roshin Raphel Avatar answered Oct 20 '22 22:10

Roshin Raphel


I had the same issue, then changed PDF options on Encryption Level: 40 bit RC4 and it helped. I think it relates with PyPDF2 module.

like image 22
Dmitrii P. Avatar answered Oct 20 '22 21:10

Dmitrii P.