PDF文件的分割和合并代码。
from PyPDF2 import PdfFileReader,PdfFileWriterdef pdf_split(filename,outputname)pr = PdfFileReader(filename)for page in range(p.getNumPages()):pw = PdfFileWriter()pw.addPage(pr.getPage(page))with open(f'{outputname}{page}.pdf','wb') as out:pw.write(out)def pdf_merge(filename,outputname):pw = PdfFileWriter()for page in range(40):pr = PdfFileReader(f'filename{page}.pdf')for page in range(pr.getNumPages()):pw.addPage(pr.getPage(page))with open(outputname,'wb') as out:pw.write(out)