Howto: Make RML templates from Openoffice.org ODT files

Report Markup Language (RML) is the ReportLAB and Open ERP format for pdf reports. It’s an XML format and it can be easy generated from web application, such as Django. Satchmo uses rml templates for shipping labels, invoices and packing slip.

One way to generate those templates it to write by hand the XML, with some difficult actions needed to generate tables and complex items.

Another easy way is to use OpenOffice.org to make the template.
The procedure is quite simple and we’ll explain it here.

First of all, generate a text odt document. If you use tables, make sure to have the same number of column for every rows. If you need a more complicated table, split it in different tables or good results will be difficult to achieve.

Format the page dimensions with openoffice, it will be the same on pdf.

In your template you must be sure to put also the text you will change, to format it to your needs. To use it in a django app, you can use the django template system placeholders like {{name}} or {{address}}.

Then, save it and use Tiny SXW2RML to transform it to RML.

./tiny_sxw2rml.py template.odt > template.rml

You can use python-trml2pdf to see the results:
apt-get install python-trml2pdf

and then
trml2pdf template.rml > template.pdf

If it’s good, you can simply replace placeholders with the text of your report (or packing slip, as we’ve done) and then generate your pdf. Using them on django apps makes RML a very good choice to generate automatically documents from databases and web apps.

About the Author

Leave a Reply