Reportlab - how to introduce line break if the paragraph is too long for a line

Vinod picture Vinod · Sep 28, 2010 · Viewed 24.3k times · Source

I have a list of text to be added to a reportlab frame

style = getSampleStyleSheet()['Normal']
style.wordWrap = 'LTR'
style.leading = 12
for legend in legends:
    elements.append(Paragraph(str(legend),style))

If the legend is too long, the text at the end is not visible at all. How to introduce line breaks in this situation.

Answer

PolyGeo picture PolyGeo · Feb 24, 2012

This may or may not apply but I just learned that \n which I normally use to introduce new lines in Python strings gets ignored by the Paragraph object of ReportLab.

From a mailing list I learned that inside Paragraph you can use HTML's <br/> to introduce the new line instead.

That works well for me.