def rl_build_story(story): from reportlab.lib.pagesizes import A4 from reportlab.platypus import SimpleDocTemplate stream = MMStringIO() doc = SimpleDocTemplate(stream, pagesize=A4) LOG.debug('building %s', repr(story)[:80]) doc.build(story) LOG.debug('build done, result is %d length.', stream.tell()) stream.seek(0, 0) return stream