[reportlab-users] Does <br /> not work in Paragraphs?
Matt Folwell
mjf at pearson.co.uk
Fri Jul 3 05:21:48 EDT 2009
Michael Hipp wrote:
> lh = Paragraph(letterhead, self.normal)
> w,h = lh.wrap(1, 1) # Find required space
> lh.drawOn(canvas, self.rightEdge-w, self.topEdge-h)
>
> The above code just wraps the lines of the address as if the <br/>
> wasn't there. Am I doing something wrong or is <br> <br>oken?
The call to wrap() is telling the Paragraph: fit yourself as best you
can in a space 1 point wide. So I'd expect it to break at every word.
The <br/> tells it to break there, which it does. It doesn't tell it not
to break anywhere else.
If you pass a larger width to wrap(), the line breaking will behave as
you want (as long as none of the lines is even longer). But the width
returned by wrap() will be the same as the width passed to it, so that
won't help you get the letterhead right-aligned.
If you really want to use a Flowable, I think you'd need to strip out
the whitespace yourself and use one of the Preformatted classes, but
personally I'd just do it with a bunch of canvas.drawRightString calls.
Matt Folwell
More information about the reportlab-users
mailing list