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

Robin Becker robin at reportlab.com
Wed Apr 12 03:38:45 EDT 2006


Eric Masson wrote:
> 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()
...... you need to wrap the paragraph. So before doing the drawOn do
a wrapOn(c,availableWidth,availableHeight)


-- 
Robin Becker


More information about the reportlab-users mailing list