specify max width to reportlab.canvas.drawString

J

juanefren

I am using reportlab to create pdf documents, everything looks fine,
how ever, is there a way to specify a max width to drawString
function ? I mean cut the sentence and continue a step down...

Cheers....
 
R

Robin Becker

juanefren said:
I am using reportlab to create pdf documents, everything looks fine,
how ever, is there a way to specify a max width to drawString
function ? I mean cut the sentence and continue a step down...

Cheers....
You'll get better results asking at the reportlab user group

(e-mail address removed)

but there are some ways to do what you want just with simple string manipulation.


Assuming you know the initial x, y and have setup a canvas with the font and
sizeand the maximum width you want.



from reportlab.lib.utils import simpleSplit
L = simpleSplit(text,canv._fontname,canv._fontsize,maxWidth)

for t in L:
canv.drawString(x,y,t)
y -= canv._leading


I haven't tested this code, but that's the principle anyway for direct drawing
to the canvas.
 
J

juanefren

You'll get better results asking at thereportlabuser group

(e-mail address removed)

but there are some ways to do what you want just with simple string manipulation.

Assuming you know the initial x, y and have setup a canvas with the font and
sizeand the maximum width you want.

fromreportlab.lib.utils import simpleSplit
L = simpleSplit(text,canv._fontname,canv._fontsize,maxWidth)

for t in L:
        canv.drawString(x,y,t)
        y -= canv._leading

I haven't tested this code, but that's the principle anyway for direct drawing
to the canvas.

It worked very good, thank you :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top