[reportlab-users] Width of Preformatted?
robin at reportlab.com
Mon Jul 26 11:55:54 EDT 2010
On 26/07/2010 16:40, Michael Hipp wrote:
> I'm doing something like this:
> text = \
> """THE BUSINESS NAME
> 31 SOME ADDRESS
> DENVER, CO 12345
> styles = getSampleStyleSheet()
> style = styles['Normal']
> cell = Preformatted(text, style)
> I need to get the actual width that will be taken up by that paragraph.
> But when I do:
> w,h = cell.wrap(1, 1,)
> It gives me something like 1,48. The second number is reasonable for the
> height, but why the bogus number for width?
> But if I try to do cell.minWidth() it says there's no such animal.
> How can I get the width of a Preformatted object?
I have a vague feeling that the wrap is bogus because this flowable just writes
whatevere you give it so it doesn't need to compute a width. Looking at the code
for preformatted it always returns what's given as the available width.
less negative we can compute using
from reportlab.pdfbase.pdfmetrics import stringWidth
w = max([stringWidth(line,fontName,fontSize) for line in cell.lines])
More information about the reportlab-users