import PyPDF2,os
pdflist=[]
path= "C:/Users/Admin/Desktop/hebin/"
dirs=os.listdir(path)
for filename in dirs:
if filename.endswith('.pdf'):
pdflist.append(filename)
pdflist.sort(key=str.lower)#按照字母顺序对列表元素排序
pdfwriter=PyPDF2.PdfFileWriter()
for filename in pdflist:
pdffile=open(path+filename,'rb')
pdfreader=PyPDF2.PdfFileReader(pdffile)
for page in range(1,pdfreader.numPages):#去除封面
pagepdf=pdfreader.getPage(page)#获取页面
pdfwriter.addPage(pagepdf)#添加页面
pdfoutput=open('C:/Users/Admin/Desktop/hebin/hebing.pdf','wb')
pdfwriter.write(pdfoutput)
pdfoutput.close()
图解Python数据结构与算法-实战篇