[reportlab-users] Re: quick hack on para.py

Dirk Holtwick holtwick at spirito.de
Wed Jul 5 06:53:13 EDT 2006

Robin Becker schrieb:
> the important one (at least for most Europeans) grrhhhhhh. I looked this
> up. According to
> http://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/symbol.txt the EURO
> SIGN has a codepoint 0x20ac, but your code is assuming 0x80 somehow. I
> think the latin1 is wrong. Things work for me if I use cp1252 throughout.
> I have added the euro as a predefined entity. That will at least allow
> you to do  €

Hi Robin,

how about adding this little helper function?

import types
def toUnicode(s):
    if type(s) is not types.UnicodeType:
        s = unicode(s, "utf8")
    return s.replace(u"\x80", u"\u20ac")

The Euro sign in my examples comes directly from my German Windows
keyboard and worked fine until now in other apps. Maybe it's a bug in

Bye, Dirk


spirito GmbH
Dirk Holtwick
Grünstraße 6
D-47051 Duisburg

fon:   +49-203-3187777
fax:   +49-203-34666896
mbx:   holtwick at spirito.de
web:   http://www.spirito.de
skype: holtwick

GnuPG fingerprint (http://www.gnupg.org)
A5A1 54E1 C82E 02AD 4804  0547 66F4 3FB0 C790 EBAB

Wichtiger Hinweis:

E-Mails können leicht verfälscht oder unter fremdem Namen erstellt
werden. Zu Ihrer und unserer Sicherheit schließen wir die rechtliche
Verbindlichkeit des vorstehenden Inhaltes aus, mithin dient der
Versand von E-Mails ausschließlich dem Informationsaustausch.
Bitte  senden Sie in Ihrem eigenen Interesse keine E-Mails in
fristgebundenen Sachen.
-------------- next part --------------
# -*- coding: ISO-8859-1 -*-

from reportlab.platypus import *
from reportlab.lib.styles import *
from reportlab.rl_config import *
from reportlab.lib.units import *
from reportlab.platypus.para import *
import os
import types

def toUnicode(s):
    if type(s) is not types.UnicodeType:
        s = unicode(s, "utf8")
    return s.replace(u"\x80", u"\u20ac")

styles = getSampleStyleSheet()

text1 = toUnicode(unicode("Über den Wolken 10,- €", "latin1"))
text2 = toUnicode(unicode("Über den Wolken 10,- €", "latin1").encode("utf8"))
print repr(text1)
print repr(text2)

program = [
    ("align", 2),
    ("size", 20),
    ("size", 10),
    #('nextLine', 0),

def test():
    doc = SimpleDocTemplate("test.pdf")
    story = []
    p1 = Para(styles["Normal"], parsedText="", bulletText=None, state=None)
    p1.program = program
    p2 = Para(styles["Normal"], parsedText=text2, bulletText=None, state=None)

if __name__=="__main__":
    os.system("start test.pdf")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 2176 bytes
Desc: not available
Url : http://two.pairlist.net/pipermail/reportlab-users/attachments/20060705/0df0a6b8/test.pdf

More information about the reportlab-users mailing list