PDF Spliter

2015, May 16    

PDf Spliter

There are many ways you can chop bulky PDF files into chewable pieces, and python is not an exception.

Run the python code presented below and type the name of the pdf file you wish to chop. Enter the start and end page number. Within a few seconds it's done and dusted.

from PyPDF2 import PdfFileWriter, PdfFileReader 
filename = str(raw_input("which file do you want to split? "))
file_to_parse = filename + ".pdf"
infile = PdfFileReader(open(file_to_parse, 'rb'))

startPage = int(raw_input("start page? ")) -1
endPage = int(raw_input("end page "))
outfile = PdfFileWriter()
for page in range(startPage, endPage):
    p = infile.getPage(page)
    outfile.addPage(p)
with open(filename+'-%03d-%03d.pdf' % (startPage+1, endPage), 'wb') as f:
    outfile.write(f)