OSX中的pyPDF IOError异常

时间:2016-02-08 20:57:36

标签: python pypdf

我正在尝试使用pyPdf模块中的PdfFileReader打开pdf(名为kalimera.pdf),使用以下命令集

from pyPdf import PdfFileReader, PdfFileWriter
document = PdfFileReader(open('kalimera.pdf', 'rb')) 

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pyPdf/pdf.py", line 374, in __init__
    self.read(stream)
  File "/Library/Python/2.7/site-packages/pyPdf/pdf.py", line 702, in read
    stream.seek(-1, 2)
IOError: [Errno 22] Invalid argument

平台是OSX 10.11.3,python版本是2.7.10(尽管这也是在python3.5中重现的。)

1 个答案:

答案 0 :(得分:0)

我不知道你为什么会收到这个错误,你正在以二进制模式阅读PDF文件并将其传递给PdfFileReader,也许你应该尝试使用其他PDF文件。

无论如何,尝试使用:https://pythonhosted.org/PyPDF2/它是最新版本的PyPDF,我认为它支持python2.7。