I am trying to combine multiple PDF files into a single PDF file using Python. I tried PyPDF and PyPDF2 - in some files they both gave the same error:
PdfReadError: EOF not found
Here my code (page_files) is a list of PDF file paths to merge:
output = PdfFileWriter()
for pf in page_files:
filestream = file(pf, "rb")
pdf = PdfFileReader(filestream)
for num in range(pdf.getNumPages()):
output.addPage(pdf.getPage(num))
outputStream = file(pdf_full_path, "wb")
output.write(outputStream)
outputStream.close()
I read several StackOverflow threads on this topic, but none of them contain a solution that works. If you have successfully combined PDF files using Python, I would like to hear how to do it. Thank!
source
share