[reportlab-users] StringWidth Units
Anthony Plunkett
anthony at thefort.org
Wed Mar 18 12:07:40 EDT 2009
New user here, I'm trying to get stringWidth to return the width of a
string in mm, and I guess my assumptions are incorrect. I thought I
could just multiply the output by the mm unit, and be done-- but doesn't
seem so:
c.stringWidth("OUTPUT","Courier",18) * mm
returns 183.69. But that clearly isn't correct, it's actually more like
23mm.
Could someone shed some light on what units it's returning, and ideally,
how to get that into mm?
Extended Example:
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import mm
from reportlab.pdfbase import pdfmetrics
c=canvas.Canvas("output.pdf",pagesize=letter)
c.setFont("Courier", 18)
c.drawString(10 * mm, 10 * mm, "OUTPUT")
print "MM:" + str(c.stringWidth("OUTPUT","Courier", 18)*mm)
print "Base Unit: " + str(c.stringWidth("OUTPUT","Courier", 18))
c.showPage()
c.save()
>>>
MM:183.68503937
Base Unit: 64.8
More information about the reportlab-users
mailing list