TRML2PDF UTF-8 issues, generating PDF off HTML insead of RML

Create issue
Issue #582 open
Former user created an issue

Package contains pretty XHTML/CSS invoices, shipping labels and packing slips making the reportlab and trml2pdf redundant. It uses a shared print and screen stylesheet.


Making pretty RML invoices is a pain. XHTML/CSS gives you much more control over the printed document than RML. New prettier browsable invoices, packing slips and shipping labels are printable straight off the browser without the need for PDF Acrobat Reader/ Reportlab of TRML2PDF or any proprietary technologies. PDF functionality is removed to improve usability and increase compatibility. Main reason for this step is that using PDF breaks usage flow and decreases productivity.

Windows Vista, Apple as well as all modern Linux distributions now provide PDF/document printers right in the box. Windows XP users (and all older Windows versions) are suggested to use CutePDF if needed.

More at: []

Frank Malina [ E-commerce development]

Reported by vizualbod

Comments (13)

  1. Former user Account Deleted

    Also the path to logo in the configuration can not be a file: anymore, I recommend an absolute path such as: /static/image/logo.gif sample-logo.bmp also needs to be a properly resized .jpeg, .gif or .png not a proprietary .bmp

  2. Former user Account Deleted
    from django.template import RequestContext
        context = RequestContext(request,
                'iconURI': icon_uri,
                'shopDetails': shopDetails,
                'shop_country': shop_country,
                'order': order,
  3. Former user Account Deleted

    I needed to add change to use RequestContext instead of Context in

    from django.template import RequestContext

    context = RequestContext(request, { 'iconURI': icon_uri, 'shopDetails': shopDetails, 'shop_country': shop_country, 'order': order, } )

  4. Chris Moffitt repo owner

    If you're still interested in it, feel free to fork and integrate these changes. Ideally I would like this to be a pluggable backend so that people that need the fine-grained pdf generation can do it while others could use a simpler HTML generated invoice.

  5. Hynek Cernoch
    • changed status to open

    Implementing UTF-8 to RML2PDF is easy. I use it. The only complication may be a general copyright to good downloadable international font, Thats why I did not send a patch.

    The charm of the existing solution is that the customer and merchant can get exactly the same formatted electronic document. A document formated by HTML has different advantages described in the references above.

    An argument concerning the existence of PDF printer driver on the desktop is not useful for a merchant or customer because neither need to generate its own PDF. Either they need to share exactly the same PDF or do not need any PDF at all.

    I like adding an optional HTML (solution supporting both formats proposed by Bojan Mihelac) but I do not like removing PDF.

  6. NM Realname

    Hynek, please tell how can be done such 'easy implementation'.

    Also, there are DejaVu, Droid or some another free international fonts, that can be used for free software without any legal problems, even if someone don't likes it.

  7. Hynek Cernoch

    An example is for font "Arial", "Times New Roman" and template invoice.rml: Everything works in UTF-8 by default.


    • Copy TTF fonts to some directory e.g. /usr/share/fonts/truetype/msttcorefonts
    • Rename files to nice names e.g. Arial_Bold.ttf
    • For every font create symbolic link to reportlab fonts.
    for f in /usr/share/fonts/truetype/msttcorefonts/*ttf; do
         ln -s $f /usr/lib/python2.5/site-packages/reportlab/fonts 

    (It is also possible to copy fonts directly to reportlab/fonts or configure reportlab to search in a specified directory but this solution was easy to remember and it allows to put international fonts in a separate directory.)

    2) Register font mapping in RML templates in Satchmo

    --- a/templates/shop/pdf/invoice.rml    2011-01-27 22:47:43.000000000 +0100
    +++ b/templates/shop/pdf/invoice.rml        2011-10-31 18:04:54.000000000 +0100
    @@ -2,6 +2,13 @@
     <!DOCTYPE document SYSTEM "rml_1_0.dtd">
     {% load i18n satchmo_currency %}
     <document filename="{{ filename }}">
    +<registerFont fontName="Times-Roman"       fontFile="Times_New_Roman.ttf"/>
    +<registerFont fontName="Arial"             fontFile="Arial.ttf"/>
    +<registerFont fontName="Arial-Bold"        fontFile="Arial_Bold.ttf"/>
    +<registerFont fontName="Arial-Italic"      fontFile="Arial_Italic.ttf"/>
    +<registerFont fontName="Arial-Bold-Italic" fontFile="Arial_Bold_Italic.ttf"/>
     <template pageSize="(21.5cm, 28cm)" leftMargin="1.0cm" rightMargin="1.0cm" topMargin="1.0cm" bottomMargin="1.0cm" title="{% trans "Store Invoice" %}" author="{{ shopDetails.store_name }}" allowSplitting="20">
         <pageTemplate id="first">

    (The default font Times-Roman is hard coded on many places in reportlab, so it was easier for me to replace it's mapping Times_New_Roman.ttf in the template.)

    3) edit/replace fonts and eventually A4 format in RML templates

    s/template pageSize="(21.5cm, 28cm)"/template pageSize="(21cm, 29.7cm)"/

    I had also a solution with modified package sources and easier templates. Nevertheless adding registerFont to templates is easy. Modified templates only can not be easy shared between users.

    Good solution for Satchmo can be to add dummy mapping to free Latin1 Vera.ttf fonts as example. All PDFs with TTF fonts are bigger than with builtin Helvetica. Then would be the recipe really easy: "Add your fonts beside Vera.ttf fonts and replace their names in templates."

    Chris, what you mean about?

  8. NM Realname

    Thanks, it works for me except two things:

    1) UnicodeEncodeError in trml2pdf/ on line 60 (fixed with replacing str() => unicode(), probably we need a patch in trml2pdf)

    2) Helvetica is also hardcoded in reportlab, besause it i've prefer remap Helvetica in template instead of changing it to Arial

    I think that we should choice some nice free fonts for default distribution and not Vera (Droid or DejaVu may be good solution).

  9. Hynek Cernoch

    Yes, I forgot to apply this patch on one development machine:

    --- a/trml2pdf/    2004-02-24 15:18:46.000000000 +0100
    +++ b/trml2pdf/    2011-01-19 02:44:39.000000000 +0100
    @@ -57,7 +57,11 @@
            for key in dict:
                    if node.hasAttribute(key):
                            if dict[key]=='str':
    -                               res[key] = str(node.getAttribute(key))
    +                               val = node.getAttribute(key)
    +                               if not isinstance(val, unicode):
    +                                       res[key] = str(val)
    +                               else:
    +                                       res[key] = val.encode('utf-8')
                            elif dict[key]=='bool':
                                    res[key] = bool_get(node.getAttribute(key))
                            elif dict[key]=='int':

    Matimatik, I dislike to study copyrights, even free copyrights, how they are compatible for redistribution and I dislike to write font installer for reportlab. Maybe you...

  10. Hynek Cernoch

    Ahh, trml2pdf-1.2.tar.gz is hosted on

    It would be easy to apply the patch to trml2pdf/ , update README.txt , (version), add a new example to rmls/ex*.rml, add a font.

    if you would have time to complete it, it would be nice.

  11. Log in to comment