[reportlab-users] Platypus - handing of plain text

Robin Becker robin at reportlab.com
Thu Feb 17 15:46:14 EST 2005


Richard Townsend wrote:
> 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:
> 
.... the text is actually supposed to be xml/sgml so & < > have a 
special meaning. You need to replace these special characters before 
passing to Paragraph. Try

text = text.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
-- 
Robin Becker


More information about the reportlab-users mailing list