[reportlab-users] Paragraphs and Spaces

snodohome at web.de snodohome at web.de
Mon Sep 18 05:10:08 EDT 2006


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



More information about the reportlab-users mailing list