Invalid pyPdf error argument

I use pyPdf to open, read and write the contents of a PDF file.

I use these lines of code for this:

from pyPdf import PdfFileWriter, PdfFileReader

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

But he returns me this error, and I don’t understand why exactly

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

Can anybody help me?

+5
source share
1 answer

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

0
source

All Articles