[reportlab-users] Printing Variable Length String
timr at probo.com
timr at probo.com
Mon Nov 5 00:54:29 EST 2007
On Sat, Nov 03, 2007 at 10:33:24AM -0700, Rich Shepard wrote:
>
> Here's the situation. For the cover page of the model report I retrieve 8
> strings from a one-line database table. One of these strings is the project
> description, and it can be of any length. What I'm trying to do is print the
> field names and values on the page something like this:
>
> Field 1: Contents
> Field 2: Contents ....
> .............
> ...........
> Field 3: Contents
>
> etc. Field 2 is the one of variable length.
>
> I can use the canvas' stringWidth() method to find the length of the Field
> 2 string, but I've not identified a Python or ReportLab function to wrap
> that string to multiple lines and allow me to identify the new Y coordinate
> for the next line.
>
> What options do I have available? Would this one page be best printed as a
> table in a platypus story?
It's possible to use a platypus Paragraph in an isolated context to do
this word-wrapping, but it really isn't that hard to do word-wrapping
on your own. You can split() the string on white space, and keep adding
words one at a time until the stringWidth() exceeds the length you want,
and then back off one word.
--
Tim Roberts, timr at probo.com
Providenza & Boeklheide, Inc.
More information about the reportlab-users
mailing list