Python 2.7 pyPdf拆分150-152页PDF后,拆分大PDF失败
我有一个函数,将PDF文件路径作为输入,并将其拆分为单独的页面,如下所示:Python 2.7 pyPdf拆分150-152页PDF后,拆分大PDF失败,python-2.7,pdf,pypdf,Python 2.7,Pdf,Pypdf,我有一个函数,将PDF文件路径作为输入,并将其拆分为单独的页面,如下所示: import os,time from pyPdf import PdfFileReader, PdfFileWriter def split_pages(file_path): print("Splitting the PDF") temp_path = os.path.join(os.path.abspath(__file__), "temp_"+str(int(time.time())))
import os,time
from pyPdf import PdfFileReader, PdfFileWriter
def split_pages(file_path):
print("Splitting the PDF")
temp_path = os.path.join(os.path.abspath(__file__), "temp_"+str(int(time.time())))
if not os.path.exists(temp_path):
os.makedirs(temp_path)
inputpdf = PdfFileReader(open(file_path, "rb"))
if inputpdf.getIsEncrypted():
inputpdf.decrypt('')
for i in xrange(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(i))
with open(os.path.join(temp_path,'%s.pdf'% i),"wb") as outputStream:
output.write(outputStream)
它适用于小文件,但问题是,当PDF超过152页时,它只在前0-151页上拆分,然后停止。在我杀死它之前,它还会吸干系统的所有内存。
请让我知道我做错了什么,或者问题发生在哪里,以及如何纠正它?问题似乎出在pyPdf本身。我切换到了pyPDF2,它工作了