[reportlab-users] UTF8 Encoded Strings

Robin Becker robin at reportlab.com
Wed Oct 31 12:15:54 EDT 2007


Rich Shepard wrote:

> On Wed, 31 Oct 2007, Robin Becker wrote:

>

>> I guess you need to use either a single utf8 encoded string or a single

>> unicode string as input to that method. This works fine

>>

>> textobject.textLine(u'This is silly!')

>>

>> the textLine method has a single argument called text.

>

> Robin,

>

> Oh. Is there then a method that allows me to print both strings in a

> tuple

> on a single line? I assumed that the textLine method would print each tuple

> as a unit.

.......
I'm not sure why the textLine method should be expected to do other than what
its documentation says eg

>

> def textLine(self, text=''):

> """prints string at current point, text cursor moves down.

> Can work with no argument to simply move the cursor down."""



The easiest way is just to add the two strings together with a separator in
between and pass that to textLine.


If as I suspect you really want this to be some kind of table then it's much
easier to be explicit and draw the strings where you want using
canvas.drawString method. You'll need to do explicit positioning, but I assume
you want to do that anyway.

Typical usage for the explicit case is

##NB I haven't tested this so take with salt

c = canvas.Canvas('mytest.pdf')
y0 = c._pagesize[1] - 72
x0 = 72
x1 = c._pagesize[0] - 72
leading = 12*1.2
c.setFont('Helvetica',12,leading=leading)

y = y0
for left,right in pairData:
c.drawString(x0,y,left)
c.drawRightString(x1,y,right)
y -= leading
if y<=72:
c.showPage()
y = y0

#all done
if y!=y0:
c.showPage()
c.save()
--
Robin Becker


More information about the reportlab-users mailing list