How to use custom fonts in RML reports?
To print report in Chinese or Comic Sans MS
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,
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 !
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.
- How to remove "Manage Databases"
- How does notifications, Inbox, To:Me, and Todo mailboxes work?
- How to define the thousands separator?
- How to be in a document's followers ?
- Which information is public in the messaging system on the bottom of documents?
- How does karma work? (odoo v8 forum software)
- Odoo Apps, Modules & Licensing FAQ
- how do I set the default value for a field from the web interface?
- How to use the OpenOffice Report Designer ( base_report_designer ) on the SaaS with XML-RPC Secure
- How to use dynamic dates in my filters? e.g. deadline date = today in project tasks
- How do I create a Partner who is a Company with several Contacts or Addresses?
- How can I create a customer with several contacts?
- How do I delete a saved filter?