Is there a way to insert a carriage return in a Paragraph in ReportLab? I am trying to concatenate a "\n" to my paragraph string but this isnt working.
Title = Paragraph("Title" + "\n" + "Page", myStyle)
I want to do this since I am putting names into cells and want to control how many names lie on a line in a cell (ideally 1). One cell can contain multiple names but within that cell i would like each name to be on its own line, hence the need to insert a new line.
At some point im getting a flowable to large for frame error (I think it has something to do with a table being too large OR having too many merged rows). The only way i can think to suppress this is to have only one name per line in a cell so that i can limit table size based on a count of names and segment the tables into smaller tables.
Seems like there has to be a much cleaner way of doing this. Any suggestions?
If you want to start a new paragraph (regardless of whether you are in a table or not), you can use the <br/>
tag. This should work for you as well:
Title = Paragraph("Title" + "<br/>" + "Page", myStyle)
(credit: Reportlab - how to introduce line break if the paragraph is too long for a line)
A Paragraph
is a Flowable
in reportlab. A newline character will not work within a flowable in the way you want it to. If your Paragraph
is within a table (as you suggest), you might consider creating a cell without a flowable. For example, you might do this:
data = [['Title\nPage', 'Name', 'Exists'], # note the newline character
['', 'George', 'True']]
t = Table(data, style=style_)
...
The above example will make the first data cell two rows tall (but part of the same cell).
If you really need to preserve the style of the Paragraph
flowable, however, you could insert two paragraphs into the same cell:
title1 = Paragraph("Title", myStyle)
title2 = Paragraph("Page", myStyle)
cell = [title1, title2] # put this in a single cell of your table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With