本文介绍了PdfReadWarning: PdfFileReader 流/文件对象不是二进制模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有很多 pdf 页面,我想将它们合并为一个文件.
I have many pdf pages that I want to merge them into one file.
我的脚本如下:
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')
当我运行它时,它给了我警告PdfReadWarning:PdfFileReader 流/文件对象不是二进制模式.它可能无法正确读取.[pdf.py:792]"
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]"
我不确定它为什么这样做.任何人都可以有任何建议吗?(我用的是pypdf2)
I'm not sure why it is doing that. Can anyone have any suggestions? (I used pypdf2)
非常感谢!
推荐答案
'rb' 应该在open",而不是 PdfFileReader.
'rb' should be on "open", not PdfFileReader.
merger.append(PdfFileReader(open(filename, 'rb')))
这篇关于PdfReadWarning: PdfFileReader 流/文件对象不是二进制模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!