[reportlab-users] UTF8 Encoded Strings

Tim Roberts timr at probo.com
Wed Oct 31 15:20:11 EDT 2007


Rich Shepard wrote:

>

> Attached is the totally re-written script to produce the page without

> using platypus, just textobjects and the canvas. It works, but it looks

> downright ugly to me, probably because of my inexperience in writing

> it more

> effectively and cleanly.

>

> Since it does work, I'd really appreciate feedback on how to write it

> better. That is, more cleanly, efficiently, and without having to find

> the

> current cursor position and use that for each new part to be written.


Printing is a tedious task, and there's just no way around it. We all
get spoiled by programs like Word and OpenOffice that let us lay out
text free-form, but when it comes to programmatically sticking pixels on
paper, someone had to keep track of where every character and line gets
placed. Personally, I like it that way. ;)

I often create my own version of the textobject class that keeps track
of the things that need tracking. I will usually have TextOut, which
draws a string and remembers where it ended, and TextOutLine that draws
a string and moves the cursor to the start of the next line. I
sometimes have Indent and Dedent methods to temporarily bump the left
margin. I do an awful lot of business forms in ReportLab, so I have
some versions that do automatic dot fill or underline fill for tables.
I have some versions that insert check boxes. I have some versions that
automatically underline the string.

I try to collect each section of the page into a function. Then I'll
have something like:

def drawLeftHandSide( self, left, top, width, height ):
# Each piece returns its "bottom". That becomes the next "top".
top = self.drawCorporateLogo( left, top, width, height )
top -= inch / 4
top = self.drawTopSummary( left, top, width, height )

def drawRightHandSide( canvas, left, top, width, height ):
...

def drawFrontPage( self, left, top, width, height ):
self.drawLeftHandSide( left, top, width/2, height )
self.drawRightHandSide( left+width/2, top, width/2, height )

--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the reportlab-users mailing list