[reportlab-users] Adding Platypus paragraphs in a canvas.

Eric Masson emss at free.fr
Tue Apr 11 11:01:57 EDT 2006


Hello,

I'm using reportlab to revamp print spools coming from an ibm midrange, 
final documents are duplexed (on recto revamped data, on verso legal 
blahblah).

So far, I've used a canvas and low level methods (lines, boxes, string 
and so on)

I'd like to use higher level objects like paragraphs to achieve a better 
presentation for the legal verso (mainly justified text).

So I tried the following snippet :
import copy
from reportlab.platypus import *
from reportlab.lib.units import cm
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.enums import TA_JUSTIFY
from reportlab.pdfgen import canvas

styles = getSampleStyleSheet()

ParaStyle = copy.deepcopy(styles["Normal"])
ParaStyle.spaceBefore = 0.2 * cm
ParaStyle.alignment = TA_JUSTIFY

def run():
     c = canvas.Canvas('paragraphtest.pdf')
     p = Paragraph("premier paragraphe de test", ParaStyle)
     p.drawOn(c, 1 * cm, 1 * cm)
     p = Paragraph("deuxième paragraphe de test", ParaStyle)
     p.drawOn(c, 1 * cm, 2 * cm)
     p = Paragraph("troisième paragraphe de test", ParaStyle)
     p.drawOn(c, 1 * cm, 3 * cm)
     p = Paragraph("quatrième paragraphe de test", ParaStyle)
     p.drawOn(c, 1 * cm, 4 * cm)
     p = Paragraph("cinquième paragraphe de test", ParaStyle)
     p.drawOn(c, 1 * cm, 5 * cm)
     c.save()

if __name__=='__main__':
     run()

But, it fails with :
Traceback (most recent call last):
   File "test.py", line 29, in ?
     run()
   File "test.py", line 17, in run
     p.drawOn(c, 1 * cm, 1 * cm)
   File 
"/usr/local/lib/python2.4/site-packages/reportlab/platypus/flowables.py", 
line 97, in drawOn
     self._drawOn(canvas)
   File 
"/usr/local/lib/python2.4/site-packages/reportlab/platypus/flowables.py", 
line 82, in _drawOn
     self.draw()#this is the bit you overload
   File 
"/usr/local/lib/python2.4/site-packages/reportlab/platypus/paragraph.py", 
line 474, in draw
     self.drawPara(self.debug)
   File 
"/usr/local/lib/python2.4/site-packages/reportlab/platypus/paragraph.py", 
line 655, in drawPara
     blPara = self.blPara
AttributeError: Paragraph instance has no attribute 'blPara'

So, two questions, is it possible to use Paragraph objects without a 
DocTemplate, If yes, what am I missing ?

Regards



More information about the reportlab-users mailing list