I have many pdf pages that I want to merge them into one file.
My script is as follow:
from PyPDF2 import PdfFileMerger,PdfFileReader
filename_list=[]
merger = PdfFileMerger()
for i in range (0,66):
filename='page'+str(i)+'.pdf'
if not filename in filename_list:
filename_list.append(filename)
for filename in filename_list:
merger.append(PdfFileReader(open(filename),'rb'))
merger.write('output.pdf')
When I ran it, it gave me the warning "PdfReadWarning: PdfFileReader stream/file object is not in binary mode. It may not be read correctly. [pdf.py:792]"
I'm not sure why it is doing that. Can anyone have any suggestions? (I used pypdf2)
Very much appreciated!
'rb' should be on "open", not PdfFileReader.
merger.append(PdfFileReader(open(filename, 'rb')))