简体   繁体   中英

Can I get the formatted text size using ReportLab in Python?

Is it possible to get the size/extents of rendered text in reportLab?

I need to calculate some positions relative to other elements on the page.

The flowable system isn't want I'm looking for. I don't mind using it to get the sizes if necessary, but it's not appropriate for my overall layout. I tried creating a Paragraph an calling wrap but it returns the available width always, not the measured extends.

You may get the width of a rendered text with stringWidth :

from reportlab.pdfbase.pdfmetrics import stringWidth
width = stringWidth(text, font_name, font_size)

Line spacing gives you the height of a line of text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM