Skip to content

Instantly share code, notes, and snippets.

@chenrui333
Created March 2, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenrui333/8203254ded93386d67dceb815ec25f4b to your computer and use it in GitHub Desktop.
Save chenrui333/8203254ded93386d67dceb815ec25f4b to your computer and use it in GitHub Desktop.
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