Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PdfReadWarning: PdfFileReader stream/file object is not in binary mode

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!

like image 774
mikayla Avatar asked Apr 01 '14 04:04

mikayla


1 Answers

'rb' should be on "open", not PdfFileReader.

merger.append(PdfFileReader(open(filename, 'rb')))
like image 162
Collin Anderson Avatar answered Nov 05 '22 05:11

Collin Anderson