Ok, I have tested this and I have to say sorry for dismissing it as an
encoding problem, the bug is definitely there but it's weirder than it
looks.
I made the test with:
controller:
def test():
response.view = 'generic.pdf'
return {}
view test.html:
{{=TABLE(TR(TD("Row's %d" % 1, _width='30%'), TD("Something",
_align="center", _width='30%'),TD("%d" % 1, _width='40%')))}}
And the problem was there, it had also converted the apostrophe to 's.
This is web2py helpers doing it btw.
If you change test.html to this:
<table>
<tr>
<td width="30%">Row's 1</td>
<td width="30%" align="center">Something</td>
<td width="40%">1</td>
</tr>
</table>
Then the problem isn't there. This shows the problem is caused by the
escaping being done by web2py helpers. It needs to be unescaped before
going to the pdf.
While trying to find the problem I found yet another problem, things are
being escaped without logic because this was what fpdf's HTMLMixin was
getting
<table><tr><td width="30%">Row&#x27;s 1</td><td align="center"
width="30%">Something</td><td width="40%">1</td></tr>
</table>
Did anyone notice the &? the ' was escaped again to &#x27;
WTF? This seems like a bug with web2py's helpers as they shouldn't escape
things that are already escaped.
Ignoring that bug there's a simple fix to be made in
gluon/contrib/fpdf/html.py make HTMLMixin escape the hell out of whatever
it gets.
class HTMLMixin(object):
def write_html(self, text, image_map=None):
"Parse HTML and convert it to PDF"
h2p = HTML2FPDF(self, image_map)
unescaped = h2p.unescape(text)
while(unescaped != text):
text = unescaped
unescaped = h2p.unescape(text)
h2p.feed(text)
This finally solved the problem for me.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.