tags:

views:

826

answers:

1

I'd like to take a multi-page pdf file and create separate pdf files per page.

I've downloaded reportlab and have browsed the documentation, but it seems aimed at pdf generation, I haven't yet seen anything about processing pdf's themselves.

Is there an easy way to do this in python?

+11  A: 

pyPdf can handle this nicely (c.f. http://pybrary.net/pyPdf/ )

from pyPdf import PdfFileWriter, PdfFileReader

inputpdf = PdfFileReader(file("document.pdf", "rb"))

for i in xrange(inputpdf.numPages):
 output = PdfFileWriter()
 output.addPage(inputpdf.getPage(i))
 outputStream = file("document-page%s.pdf" % i, "wb")
 output.write(outputStream)
 outputStream.close()

etc.

Great! Does just what I wanted thanks!
monkut
@bluce: I read this yesterday and used it at work today. +1!
technomalogical