Python
PDF Splitter
The PDF Splitter Tool is handy for instances where I want to quickly split up the pages of a PDF into individual files, e.g.
The code is writting in Python using the PyPDF2 library for the splitting function. I used easygui for the file path operations so it can be used on any OS. Unfortunately it can't split encrypted files at this point.
from PyPDF2 import PdfFileReader, PdfFileWriter from pathlib import Path import easygui def selectpdf(): fileopenlocation = easygui.fileopenbox(msg='Please select a pdf', title='Specify File') #print(fileopenlocation) if(str(fileopenlocation)=='None'): #print('Nothing selected') return if(str.lower(fileopenlocation[-3:])!='pdf'): easygui.msgbox("File must be a PDF", title="Error") fileopenlocation = '' selectpdf() #print(str(filelocation[-3:])) input_pdf = PdfFileReader(str(fileopenlocation)) filesavelocation = filesaveloc() #print(str(filesavelocation)) pageqty = input_pdf.getNumPages() pdf_writer = [None] * pageqty for n in range(0, pageqty): pdf_writer[n] = PdfFileWriter() #print(pageqty) #Creating the new PDFs for n in range(0, pageqty): #print(n) page = input_pdf.getPage(n) pdf_writer[n].insertPage(page,0) with Path(filesavelocation + '_pg' + (str(n+1)) + '.pdf').open(mode="wb") as output_file: pdf_writer[n].write(output_file) def filesaveloc(): filesavelocation = easygui.filesavebox(msg='Select output location', title='Output PDFs') return filesavelocation if __name__ == "__main__": selectpdf()