Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

6

How to use custom fonts in RML reports?

By
Martin Trigaux (mat)
on 12/19/14, 5:03 AM 4,162 views

To print report in Chinese or Comic Sans MS

This question has been included in the official documentation.
6

Martin Trigaux (mat)

--Martin Trigaux (mat)--
1775
| 6 4 7
Grand Rosiere, Belgium
--Martin Trigaux (mat)--

Community manager: help with the code and translations contributions from the community on GitHub and Transifex.

Developed the gamification module and is also now responsible of the documentation and Point of Sale.

Martin Trigaux (mat)
On 12/19/14, 5:05 AM

Some languages (e.g. Chinese) needs different charset not supported by classic fonts (or you just want Comic Sans MS in your reports). Good news, you can use custom TTF fonts. For Chinese, we make it easier for Sun-ExtA but you can use any TTF font,

Version 7.0

 

The list of available fonts is hardcoded in CustomTTFontsvariable in openerp/report/render/rml2pdf/customfonts.py. If you want to add another font than DejaVu Sans, Liberation Serif, FreeMono or Sun-ExtA, you will need to modify the source file to add the font in the format:

('family name', 'font name', 'ttf file name', 'mode')
  • family name: the name of font interpreted by reportlab (e.g. check with FontForge Element > Font Info)
  • font name: what should be put in your rml file. Family name can common between several fonts while font name should be unique (e.g. "DejaVu Sans" vs "DejaVu Sans Bold")
  • file name: just the name of your ttf file, not the full patch
  • mode: one between normal, italic, oblique, bold, bolditalic, bold italic, boldoblique, bold oblique or all

Careful: the font and file names are case sensitive !!!

To be discovered by odoo, your font should be in one of these folders

'/usr/share/fonts/truetype',
'/usr/share/fonts/dejavu',
'/usr/share/fonts/liberation',
'/usr/share/fonts/truetype/*',
'/usr/share/fonts/TTF/*',
'/usr/share/fonts/TTF',
'c:/winnt/fonts',
'c:/windows/fonts',
'~/Library/Fonts',
'/Library/Fonts',
'/Network/Library/Fonts',
'/System/Library/Fonts',
  • the search folders defined in reportlab library, variable TTFSearchPath (e.g.~/.fonts on linux, check /usr/lib/python2.7/site-packages/reportlab/rl_settings.py for full list)

When rendering a report, check your logs (debug mode helps) for warning or info message about fonts not found. Restarting your odoo server after installing a font may help.

To use your font on every report modify the RML Header of your company (Settings > Companies > Header/Footer) and change and locate the fontName="DejaVu Sans" or setFont name="DejaVu Sans" to replace by the font name you wish to use.

This will only modify global settings, if you have font specified inside the rml reports, you will also need to modify these one !

 

Version 8.0

No more needed to modify python files ! Well actually no more need to do RML reports in v8 but still possible.

You still need to install the custom font in one of the searched folder (see above).

Go to Settings > Companies > Report Configuration and hit the reload fonts button to populate the many2one (by default empty). odoo will scan all the fonts installed on your system. Selecting one will modify the company headers to use it globally.

 

Let me add one note: the installed should be .ttf format. .ttc will not be scanned or listed. e.g ttf-wqy-microhei which is popularly used for chinese, has the ttc extension by default. To fix it, just rename the ttc extension to ttf will do the trick~

youring
on 12/19/14, 10:24 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 12/19/14, 5:03 AM
Seen: 4162 times
Last updated: 3/10/16, 3:54 PM