[reportlab-users] sizes of fonts and images

Luc Saffre luc.saffre at gmx.net
Mon Oct 23 16:26:14 EDT 2006


Hello,

I try to render a text in monospaced font together with an image.
And I want the image to be exactly as wide as the line of text.

Images and fonts apparently use different units because the following
script renders the image too big (its width is about 1.5 times the text
width):

import os
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm
filename="tmp.pdf"
X=30
canvas = canvas.Canvas(filename)
canvas.setFont("Courier", 10, leading=11)
t=canvas.beginText()
t.setTextOrigin(20*mm,200*mm)
t.textOut('-'*X)
canvas.drawText(t)
canvas.drawImage("logo.jpg",
                 x=20*mm,y=200*mm-11*X,
                 width=10*X,height=11*X)
canvas.save()
os.startfile(filename)

How must I specify the with of my image if I know that it must be 30
characters wide, and that the font size is 10?

Thanks for any ideas.
Luc


More information about the reportlab-users mailing list