PDF文件分割合并

PDF文件的分割和合并代码。

from PyPDF2 import PdfFileReader,PdfFileWriter

def 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)

你可能感兴趣的:(办公自动化,pdf,python)