Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Scripts Collections
#! /usr/bin/python
# reference: http://stackoverflow.com/questions/39574096/how-to-delete-pages-from-pdf-file-using-python
import glob
from PyPDF2 import PdfFileWriter, PdfFileReader
for fname in glob.glob('./*.pdf'):
infile = PdfFileReader(fname, 'rb')
output = PdfFileWriter()
print("file name:", fname, "with pages: ", infile.getNumPages())
# getNumPages() starts with 0
for i in range(1, infile.getNumPages()):
p = infile.getPage(i)
output.addPage(p)
with open(fname, 'wb') as f:
output.write(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.