'&' character in text

45 views
Skip to first unread message

Joel B. Mohler

unread,
Sep 11, 2010, 9:36:13 AM9/11/10
to geraldo-users
I have text with the ampersand character in it that is getting
mutilated when I generate a report. I modified the first example from
the tutorial and am getting the same problem:

from geraldo import Report, DetailBand, ObjectValue
from geraldo.utils import cm
from geraldo.generators import PDFGenerator
names = ['PP&L', 'Sticks & Stones', '&&&']
class MyReport(Report):
class band_detail(DetailBand):
height=0.7*cm
elements=[
ObjectValue(attribute_name='capitalize'),
]
report = MyReport(queryset=names)
report.generate_by(PDFGenerator, filename='ampersand.pdf')

The output I get is at http://kiwistrawberry.us/ampersand.pdf
A copy of the above source is at http://kiwistrawberry.us/tg.py

I tried to read the source code to see what is going on, but didn't
get very far. I thought maybe the unicode conversions where ruining
my ampersands, but experimentation at the interactive python prompt
did not confirm any of that.

Do I need to escape the '&' characters? Do I need to change some
settings?

Thanks, Joel

Adrian Klaver

unread,
Sep 11, 2010, 1:19:38 PM9/11/10
to gerald...@googlegroups.com, Joel B. Mohler

This is coming from ReportLab. The default Paragraph class does not escape '&'
properly when creating the XML representation of the report. When using
ReportLab directly I do:

from reportlab.platypus import para

and then:

para.Paragraph()

This uses a newer version of the Paragraph class that handles escaping properly.

--
Adrian Klaver
adrian...@gmail.com

Joel B. Mohler

unread,
Sep 11, 2010, 3:53:25 PM9/11/10
to geraldo-users
> This is coming from ReportLab. The default Paragraph class does not escape '&'
> properly when creating the XML representation of the report. When using
> ReportLab directly I do:

I escaped my '&' with
.replace("&", "&")
but I'm a little uncertain if that's something that is required
permanently. It does fix it for the moment though. It's certainly
not what I'd consider optimal to have to insert escaping calls in my
ObjectValue get_value for everything.

Before I learned of geraldo, I had written some things directly to
reportlab, it appears to not need escaping in those reports. Perhaps
that is because I was not using the Paragraph type there, I was
inserting my data directly in a table ... not sure if that made any
sense.

> from reportlab.platypus import para
>
> and then:
>
> para.Paragraph()

Are you saying that this is a fix that should be applied to geraldo or
is that a bug in ReportLab that will get fixed soon?

--
Joel

Adrian Klaver

unread,
Sep 13, 2010, 5:39:40 PM9/13/10
to gerald...@googlegroups.com

Not sure where the best place to fix it is. I thought I filed an issue with this
on the Geraldo site, but I cannot seem to find it. Seems there may also be a
ReportLab issue see this message on the ReportLab mailing list:
http://two.pairlist.net/pipermail/reportlab-users/2010-September/009732.html

>
> --
> Joel

--
Adrian Klaver
adrian...@gmail.com

Reply all
Reply to author
Forward
0 new messages