python PyPDF2 剔除pdf中指定页

from PyPDF2 import PdfFileReader, PdfFileWriter
 
readfile=r"D:\1\3.pdf"   #源文件路径
outfile=r"D:\1\1.pdf"     #剔除后文件路径
 
pdfReader = PdfFileReader(open(readfile, 'rb'))
pdfFileWriter = PdfFileWriter()
numPages = pdfReader.getNumPages()
pagelist=(1,)   #注意第一页的index为0.
for index in range(0, numPages):
    if index not in pagelist:
        pageObj = pdfReader.getPage(index)
        pdfFileWriter.addPage(pageObj)
pdfFileWriter.write(open(outfile, 'wb'))

你可能感兴趣的:(python PyPDF2 剔除pdf中指定页)