3
我在Windows平臺上使用Python 2.4和PyPdf 1.13。 我想從列表合併PDF文件合併成一個使用下面的代碼:Python中Pypdf軟件包中的聲明錯誤
import os
from pyPdf import PdfFileWriter, PdfFileReader
attached=["C:\\test\\T_tech.pdf","C:\\test\\00647165-Backup.pdf"]
output=PdfFileWriter()
maxpage=0
os.chdir("C:\\test")
name= attached[0]
name = os.path.basename(name).split('.')[0]
for nam in attached:
input= PdfFileReader(file(nam,"rb"))
maxpage=input.getNumPages()
for i in range(0,maxpage):
output.addPage(input.getPage(i))
outputStream =file("Output-"+name+".pdf","wb")
output.write(outputStream)
outputStream.close()
當我運行這段代碼我收到以下錯誤。
Traceback (most recent call last):
File "C:\Python24\pdfmerge.py", line 13, in ?
input= PdfFileReader(file(nam,"rb"))
File "C:\Python24\Lib\site-packages\pyPdf\pdf.py", line 374, in __init__
self.read(stream)
File "C:\Python24\Lib\site-packages\pyPdf\pdf.py", line 847, in read
assert False
AssertionError
任何幫助,非常感謝。
這可能與他使用Python 2.4的事實有關。我無法在Windows上重現Python 2.7.2的錯誤。 – jsalonen
嗨,布萊恩,謝謝你的嘗試。我試着通過評論它,但仍然沒有改變。 – gaya3
「不變」?這似乎不太可能。至少,如果你以某種方式觸及另一個斷言失敗,它應該在另一條線上。 –