PyPDF2 split pdf by pages
You can use the write
method of the PdfFileWriter
to write out to the file.
from PyPDF2 import PdfFileReader, PdfFileWriter
with open("input.pdf", 'rb') as infile:
reader = PdfFileReader(infile)
writer = PdfFileWriter()
writer.addPage(reader.getPage(0))
with open('output.pdf', 'wb') as outfile:
writer.write(outfile)
You may want to loop over the pages of the input file, create a new writer object, add a single page. Then write out to an ever incrementing filename or have some other scheme for deciding output filename?