Apologies if this has been previously asked, but I couldn’t find exactly what I am trying to do. I have a large PDF that consists of a batch of 100 2-page forms (each different form has a unique identifier). I would like to split this up so that pages 1-2 are in a new file, 3-4 in a new file, and so on. How would I edit the following code to allow for this? Currently it splits each individual page into a separate file.
from pyPdf import PdfFileWriter, PdfFileReader
inputpdf = PdfFileReader(file("abc.pdf", "rb"))
for i in range(inputpdf.numPages):
output = PdfFileWriter()
output.addPage(inputpdf.getPage(i))
outputStream = file("abc-page%s.pdf" % i, "wb")
output.write(outputStream)
outputStream.close()
I think this is what you want. I haven’t verified it, YMMV, etc.