I am using Python 2.4 and PyPdf 1.13 on a Windows platform. I am trying to merge PDF files from a list into one using the following code:
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()
I am getting the following error when I run this code.
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
Any help is greatly appreciated.