Created
March 2, 2017 14:37
-
-
Save chenrui333/8203254ded93386d67dceb815ec25f4b to your computer and use it in GitHub Desktop.
Python Scripts Collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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