[reportlab-users] Finding out the width/height of text

Jotham jotham.read at gmail.com
Tue Jan 19 06:49:01 EST 2010


Hi guys,

I guess I wasn't very clear. It's important for me that I also know both
the width and the height of the text. I require the entire bounding
rectangle for the given input string at the given style. Right now it is a
single line. Maybe later it is going to need to wrap within a pair of
margins.

On Tue, Jan 19, 2010 at 2:52 AM, Meitham Jamaa <meitham at reportlab.com>wrote:


> Jotham wrote:

> > Hello,

> >

> > I am wanting to use ReportLab to generate both a bitmap (for live preview

> in

> > a client application) and PDF for dispatch to a printer. I have a client

> > application that allows some basic alterations to be made by the user,

> for

> > this to work I need to be able to find out some geometry information for

> a

> > given piece of text at a given font and style. I can't see how to do

> this

> > in ReportLab. Ideally I would be able to render out just the text in

> > question to a bitmap surface of some kind, work with that, and once

> > everything is finalised generate the PDF.

>

> If you text is one line string then you can use

> from reportlab.pdfbase.pdfmetrics import stringWidth

> textWidth = stringWidth(text, fontName, fontSize)

>

> If your text was multi-lines, assuming you are working in a rectangular

> area with defined width,

> then do

>

> from reportlab.lib.utils import simpleSplit

> lines = simpleSplit(text, fontName, fontSize, maxWidth)

>

> lines is a list of all the lines of your paragraph, if you know the line

> spacing value then the

> height of the paragraph can be calculated as lineSpacing*len(lines)

>

> I hope this helps

> Meitham

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at lists2.reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100120/c5a6501a/attachment.htm>


More information about the reportlab-users mailing list