[reportlab-users] question re: paragraph bounding box vertical offset

Chris Jerdonek chris.jerdonek at gmail.com
Sun Aug 29 13:59:22 EDT 2010

Hi, I'm new to ReportLab and have a quick question.

My question is about the location of a paragraph's bounding box with
respect to the text it contains.

I've been doing some experiments, and it seems like a paragraph's
bounding box is never flush with the text it contains. It seems like
the box is usually offset upwards a distance equal to a bit more than
a third of the "leading" for lines in the paragraph (e.g. when the
paragraph style has autoLeading='min').

I'm attaching a PDF with examples for font sizes 24pt and 12pt. In
each case, you can see that the last line of text protrudes past the
bottom border of the paragraph's bounding box. There is also an
approximately equal amount of vertical white space between the top
text and the top border (even with borderPadding=0).

For reference, I'm including the important part of the code at bottom.

Can anyone provide an explanation of this behavior?

Thanks a lot for your help,

sample_style_sheet = getSampleStyleSheet()

para1_style = ParagraphStyle(
name = 'Test1',
parent = sample_style_sheet['BodyText'],
fontSize = 12,
borderColor = 'black',
borderWidth = 1,
borderPadding = 0,
autoLeading = 'min',
leading = 100, # Has no effect because of autoLeading 'min'.

para2_style = ParagraphStyle(
name = 'Test2',
parent = para1_style,
fontSize = 24,

text = """Silly example.\nSilly example."""

para1 = Paragraph(text, para1_style)
para2 = Paragraph(text, para2_style)

para1.wrap(75, 0)
para2.wrap(150, 0)

para1.drawOn(canvas, 72, 72) # One inch from bottom of the page.
para2.drawOn(canvas, 72, 110)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: paragraph_offset_example.pdf
Type: application/pdf
Size: 2157 bytes
Desc: not available
Url : <http://two.pairlist.net/pipermail/reportlab-users/attachments/20100829/47734ae4/attachment.pdf>

More information about the reportlab-users mailing list