[reportlab-users] Special characters in text

Robin Becker robin at reportlab.com
Wed Sep 28 09:26:20 EDT 2005


Dick Kniep wrote:
> Hi list,
> 
> Probably this has been asked before, but I cannot find it in the archives.
> 
> We are using reportlab to generate PDF's and this works nicely. However, data 
> used is entered by users, so there is no way of knowing what data will be 
> there. Now if some of the data contains an & or an % sign, the application 
> crashes. I use the following command to add the text to the report:
> 
> Paragraph(fld,parStyle)
> 
> Hope someone knows how to deal with this.
> 
> Cheers,
> Dick
.....

you can escape all the < & > fairly easily. eg

fld=fld.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')

should eliminate most problems.
-- 
Robin Becker


More information about the reportlab-users mailing list