Lino Website

Problem reports

sizes of fonts and images

Monday, 23. October 2006 23:26.

Another problem reported in prn2pdf renders box characters (21.10.06) was the fact that prn2pdf doesn't correctly size the image in 5.prn.

I asked help from reportlab-users@reportlab.com:

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

Refering articles:

Copyright 2001-2007 Luc Saffre.
http://lino.saffre-rumma.ee
Generated 2007-06-07 16:22:52