reportlab low performance


/ Published in: Python
Save to your folder(s)

So, when I try to set the BYTES_TO_READ variable to more than 200-300 thousands (i.e., just to see what happening, not reading the full book, just some part of it) - it takes HUGE amount of time...


Copy this code and paste it in your HTML
  1. BYTES_TO_READ = 10000
  2.  
  3. def go(text):
  4. doc = SimpleDocTemplate("output.pdf")
  5. Story = [Spacer(1, 2*inch)]
  6. style = styles["Normal"]
  7. p = Paragraph(text, style)
  8. Story.append(p)
  9. doc.build(Story)
  10.  
  11. def get_text_from_file():
  12. source_file = open("book.txt", "r")
  13. text = source_file.read(BYTES_TO_READ)
  14. source_file.close()
  15. return text
  16.  
  17. go(get_text_from_file())

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.