[reportlab-users] paragraph height
Gustavo Henrique Cervi
gustavohc at gmail.com
Tue Nov 27 06:50:57 EST 2007
great.
import reportlab, reportlab.lib.styles, reportlab.lib.pagesizes,
reportlab.platypus
style = reportlab.lib.styles.getSampleStyleSheet()
pdf = reportlab.platypus.SimpleDocTemplate("/dev/null", pagesize =
reportlab.lib.pagesizes.A4)
w = reportlab.lib.pagesizes.A4[0] - (pdf.leftMargin + pdf.rightMargin)
p = reportlab.platypus.Paragraph("xxxxxx "*400, style["Normal"])
p.wrap(w, w)
result: (451.27559055118104, 372)
372/reportlab.lib.units.cm
result: 13.123333333333333
Is this value accurate or aprox?
-Gustavo
Robin Becker wrote:
> Gustavo Henrique Cervi wrote:
>> Hi.
>>
>> How can I to get the height of an paragraph (platypus)?
>> If the paragraph is too short, I want to compensate increasing the
>> linespacing (leading) to fill the whole page, otherwise, I can
>> decrease the linespacing to fit the text into a single page.
>>
>> Thanks.
>>
>> -Gustavo
> ......
>
>
> If you know the width at which you wish to write the paragraph, P, the
> wrap call will give you a good estimate of it's height eg
>
> w, h = P.wrap(availableWidth,100000)
>
> where 100000 is the height we allow (I assume your paragraph would be
> shorter). Given the height you may choose to adjust leading and//or
> fontSize to get the required layout.
More information about the reportlab-users
mailing list