[reportlab-users] Platypus - handing of plain text

Richard Townsend richard at reticulatus.plus.com
Thu Feb 17 14:08:41 EST 2005


One of my colleagues has been using Platypus to generate .pdf documents 
which contain plain text we receive from a third party.

The text may contain anything and this is causing problems with the 
Paragraph class which falls over if it hits something like a single 
ampersand '&' character because the parser rejects it as invalid XML.

Is there a way to make the Paragraph class treat the text argument as 
plain text? Or is there an alternative to Paragraph that we should be using?

This simple code shows the error we get:

--------
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet

styles = getSampleStyleSheet()
style = styles["Normal"]
text = "Cat & mouse"
p = Paragraph(text, style)

Traceback (most recent call last):
  File "test_bug.py", line 7, in ?
    p = Paragraph(text, style)
  File "C:\Python24\lib\site-packages\reportlab\platypus\paragraph.py", 
line 378
, in __init__
    self._setup(text, style, bulletText, frags, cleanBlockQuotedText)
  File "C:\Python24\lib\site-packages\reportlab\platypus\paragraph.py", 
line 403
, in _setup
    raise "xml parser error (%s) in paragraph beginning\n'%s'"\
xml parser error (bogus < or &) in paragraph beginning
'Cat & mouse'

---------------
regards
Richard Townsend




More information about the reportlab-users mailing list