doc.set_parser(parser)
doc.initialize('')
interpreter = PDFPageInterpreter(rsrc, device)
for i, page in enumerate(doc.get_pages()):
    outfp.write('START PAGE %d\n' % i)
if page is not None:
    interpreter.process_page(page)
outfp.write('END PAGE %d\n' % i)
device.close()
fp.close()
return outfp.getvalue()
Python module for converting PDF to text