python3截取PDF文件中的一部分。
from PyPDF2 import PdfFileWriter, PdfFileReader# 开始页start_page = 0# 截止页end_page = 5output = PdfFileWriter()pdf_file = PdfFileReader(open("input.pdf", "rb"))pdf_pages_len = pdf_file.getNumPages()# 保存input.pdf中的1-5页到output.pdffor i in range(start_page, end_page): output.addPage(pdf_file.getPage(i))outputStream = open("output.pdf", "wb")output.write(outputStream)