Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyPdf error invalid argument

I'm actually using pyPdf to open, read and write the content of a PDF file.

for that I use these lines of code :

from pyPdf import PdfFileWriter, PdfFileReader

pdf = PdfFileReader(file("/myPdfFile.pdf", "w+b"))
content = pdf.getPage(1).extractText()
print content

But it returns me this error and I don't understand exactly why

File "/usr/local/lib/python2.6/dist-packages/pyPdf/pdf.py", line 374, in __init__
    self.read(stream)
File "/usr/local/lib/python2.6/dist-packages/pyPdf/pdf.py", line 702, in read
    stream.seek(-1, 2)
IOError: [Errno 22] Invalid argument

Anyone can help me?

like image 807
kschaeffler Avatar asked May 22 '12 17:05

kschaeffler


1 Answers

As it says in the Python docs, the mode 'w+b' opens and truncates the file to 0 bytes, while 'r+b' opens the file without truncation.

like image 146
MRAB Avatar answered Oct 06 '22 05:10

MRAB