[reportlab-users] Paragraph vertical offset?

Buganini buganini at gmail.com
Wed Jan 9 19:55:12 EST 2013


Hi, I'm tring to use paragraph with border:

# -*- coding:utf-8 -*-
from reportlab.lib import colors
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.pdfgen import canvas
from reportlab.platypus import Paragraph
a="""aaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaa
aaaaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaa aaaaaaaaaa
bbbbbbbbbbbbb cccccccccccccc dddddddddddd eeeeeeeeee fffffffffffff
gggggggggggggg hhhhhhhhhhhhhhh jjjj jjjjj"""

styles=getSampleStyleSheet()
c=canvas.Canvas("lala.pdf")
style=styles["Normal"]
print dir(style)
style.fontSize=100
#style.borderWidth=0.5
#style.borderColor = colors.toColor('red')
p=Paragraph(a, style)
mw=300
mh=100
w,h=p.wrap(mw,mh)
print (w,h,p.style.fontSize)
while w>mw or h>mh: //shrinkToFit
style.fontSize-=0.5
if style.fontSize<0:
break
p=Paragraph(a, style)
w,h=p.wrap(mw,mh)
p.drawOn(c, 20,700)
print (w,h,p.style.fontSize)

c.rect(20,700,mw,mh)

c.showPage()
c.save()

but it appears to have some weird vertical offset, I've checked "class
ParaBox2" in rl_doc_utils.py, there is nothing special but some hardcoded
calculation (*10.0/9.0 *0.95), even if I apply those calculation, there is
still incorrect offset.

Could someone give me an idea?

BTW, is there a way to tell paragraph to keep original linebreaks?

--Buganini
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20130110/86dad493/attachment.html>


More information about the reportlab-users mailing list