0

I'm following the book 'Automate the boring stuff' and on chapter 15 I ran into a problem. It should be a very simple program to unlock a decrypted file using a password but it just won't work for me. I've looked up solutions to this problem. The solutions where to use the open function with 'rb' I did that but still get the same error. All help is appreciated!

import PyPDF2 

pdfReader = PyPDF2.PdfFileReader(open('C:\\Path\\to\\the\\file\\encrypted.pdf'),'rb')
pdfReader.decrypt('rosebud')

Error:

io.UnsupportedOperation: can't do nonzero end-relative seeks
deceze
  • 510,633
  • 85
  • 743
  • 889

1 Answers1

1

Duplicate of this post : UnsupportedOperation: can't do nonzero end-relative seeks : Python - PyPDF2

Correct use is : pdfReader = PyPDF2.PdfFileReader(open('PATH_TO_PDF','rb'))

You may have a new error if you encrypt your pdf with Acrobat6 (see reported issue in PyPDF2 github).

Nicos44k
  • 88
  • 7
  • The duplicate post I already saw, But the second article you gave relating to Acrobat6 did help, The solution was to open the file with pikepdf, then save that file and open it again but with PyPDF2. https://github.com/mstamy2/PyPDF2/issues/378#issuecomment-689585779 – Mats Janssens Aug 19 '21 at 06:12