python——提取pdf中的指定页

from PyPDF2 import PdfFileWriter, PdfFileReader
 
# 开始页
start_page = 0
 
# 截止页
end_page = 5
 
output = PdfFileWriter()
pdf_file = PdfFileReader(open("3.pdf", "rb"))
pdf_pages_len = pdf_file.getNumPages()
 
# 保存input.pdf中的1-5页到output.pdf
for i in range(start_page, end_page):
 output.addPage(pdf_file.getPage(i))
 
outputStream = open("output.pdf", "wb")
output.write(outputStream)

转发自:https://www.jb51.net/article/149587.htm

posted @ 2021-03-07 00:26  朵朵奇fa  阅读(1961)  评论(0编辑  收藏  举报