[reportlab-users] Paragraphs and Spaces

Tim Roberts timr at probo.com
Mon Sep 18 12:57:36 EDT 2006


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"]
>  
>

This is NOT one paragraph.  This is a paragraph, a numbered list, three
indented paragraphs, and non-indented paragraph.

You can't have it both ways.  Either your text is pre-formatted, or it
is not pre-formatted.  It would not be hard to break your text into
paragraphs (by splitting on newlines), and then parse each paragraph to
determine what kind of formatting to apply.  Either that, or do the
line-wrapping on your own, and write it out as pre-formatted.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the reportlab-users mailing list