[reportlab-users] Paragraphs and Spaces

Rob Schall rschall at callone.net
Mon Sep 18 08:43:12 EDT 2006


There probably is a better solution than this one, but since I'm still 
newer to reportlab, I just threw something together.

In short, I don't believe its possible. You have to break it up into 
several paragraphs. All of the numbered stuff I had in an array 
actually. Then I looped threw it and positioned all of that text about 
20points from the normal margin. The numbers were placed separately by 
getting the height of the paragraph about to be written and writing it 
at the left margin and at the top height of the paragraph.

Kind of a messy way to do it, but I don't figure out a better way to 
handle this.

Rob Schall

snodohome at web.de wrote:
> The Paragraph-object strips all spaces but I need to explicitely set some.
> I would use XPreformatted. But there is no automatic wrapping - I have something like a semi-preformatted text.
> Look at my example-code. My problem is described in that text ;)
>
>
>
> from reportlab.pdfgen.canvas import Canvas
> from reportlab.platypus import Paragraph
> from reportlab.lib.styles import getSampleStyleSheet
> from reportlab.lib.units import cm
>
> c = Canvas("nbsp_test.pdf")
>
> text = "This is my text-block which is usually read from a database. "\
>        "Normally its width is larger than my available width - so I need to wrap it. "\
>        "I tried to use XPreformatted but the automatic wrapping didn't work. So I changed back to normal Paragraph-objects. "\
>        "But now I noticed that I can't use non-breaking spaces or tabs or something like this in it - look:\n"\
>        "1.  this should be some kind of info\n"\
>        "    with some text in the second line - trying to use normal spaces\n"\
>        "    and some more in the third line - this time trying to use non-breaking spaces like they're used in HTML\n"\
>        "\tand finally trying to use a tab in the fourth line\n\n"\
>        "All of these 3 types of spaces are ignored by a Paragraph-object.\n"\
>        "Is there any solution for my problem?"
> style = getSampleStyleSheet()["Normal"]
>
> text = text.replace("\n", "<br />")
> para = Paragraph(text, style)
> x, y = para.wrap(18*cm, 10*cm)
>
> y = 28*cm - y
> para.drawOn(c, 1*cm, y)
>
> c.save()
>
> __________________________________________________________________________
> Erweitern Sie FreeMail zu einem noch leistungsstärkeren E-Mail-Postfach!		
> Mehr Infos unter http://freemail.web.de/home/landingpad/?mc=021131
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>   



More information about the reportlab-users mailing list