2016-02-08 27 views
0

我試圖用PdfFileReader從pyPdf模塊打開PDF(名爲kalimera.pdf),使用下面的命令集pyPDF IOError異常在OSX

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中重現的)。

+0

您是否嘗試過多個PDF文件供您參考?我已經在Python 2.7.4中嘗試了一個PDF示例,我似乎沒有得到'IOError' ... – summea

+0

你是指多個PDF? 它不適用於我在工作目錄中的任何pdf文件。 – bergercookie

回答

0

我不知道你爲什麼會得到這個錯誤,你正在用二進制模式閱讀PDF文件並將它傳遞給PdfFileReader,也許你應該嘗試使用其他PDF文件。

無論如何,儘量使用:https://pythonhosted.org/PyPDF2/其最新版本的PyPDF,我認爲它支持python2.7。