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.

3

How to add custom fonts to QWeb reports?

By
Yenthe
on 7/30/15, 8:06 AM 5,196 views

Hi guys,

Has anybody had any succes adding a custom font to a QWeb report?
My initial idea was to add a CSS file that references the font file but that doesn't seem to work. In my module I've made static/src/css and added a file mylayout.css. In this file I've added the following:

 @font-face 
{
    font-family: cool_font;
    src: url('nexa.otf');
}
h1
{
font-family:cool_font;
color:blue;
text-align:center;
}

I've added the CSS file to my __openerp__.py:

 # any module necessary for this one to work correctly
    'depends': ['sale','project','product'],

 'css':'static/src/css/usentric.css',
    'data': [
        # 'security/ir.model.access.csv',
	'linker_report.xml',
        'views/report_saleorder_expand.xml',
        'templates.xml',
	#This creates the default items in the model sale.order.printorder, so we don't ever have to create it manually.
	'defaultdata.xml',
	'security/ir.model.access.csv',
    ],
    # only loaded in demonstration mode
    'demo': [
        'demo.xml',
    ],

But doing so did not change anything to my report. Neither the font is used and neither is the color applied. So then I decided to give it a try with inline css (style). My code:

<h1 style="font-family:cool_font; src:url('nexa.otf');">This is to test my custom font.</h1> 

But this doesn't work either. I've added the .otf file on the same level as the XML report file. I'm 100% sure the code works because I've tested this in a basic HTML page and the font is rendered.
So, what am I missing / doing wrong and has anybody got this working?


Thanks,
Yenthe

@Yenthe, Can you please answer this query of mine. Thanks. https://www.odoo.com/forum/help-1/question/odoo9c-how-to-add-custom-fonts-to-qweb-reports-104960

deep
on 7/19/16, 9:55 AM
4

Axel Mendoza

--Axel Mendoza--
10263
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 7/30/15, 8:59 AM

Hi Yenthe

First the css that you declare in the file mylayout.css is not used because of this:

css and style declarations It's working ok, just a little more hard than expected, I just test it locally by modifying the saved view in the database for my working layout view(website module override original report layout) to add my style(ugly yeah), the scenario work by collecting the styles defined in the head of the report document, as you said is not working for the body of the report document, at least for pdf, for html is ok. The way to go is extend the report layout to add your css files or styles to the head or create a new report layout to ensure that your css is loaded in the head only for your target report template. I test it by changing the color and it works in html and pdf reports. The same apply for your needs. With that fixed you could now try again all the methods for including your custom font, including the following:

Second your custom font won't will be picked by wkhtmltopdf, but you could declare it in another way. for example:

Full explanation here:

http://blog.shahariaazam.com/use-google-web-fonts-for-wkhtmltopdf-tools/

<style type="text/css"> 
@font-face {     font-family: cool_font;     font-style: normal; font-weight: 400; src: url(data:font/opentype;charset=utf-8;base64,d09GRgABAAAAAD00AA4A---[large string ommited]----3MAuAH/hbAEjQA=) format("woff"), url(data:font/truetype;charset=utf-8;base64,AAEAAAARAQAABAAQRFNJRwAAAAEAAJUIAAA---[large string ommited]-----wAAAAAAAAAAAAEAAAAA) format("truetype");
} h1{     font-family:cool_font;     color:blue;     text-align:center;  }
</style>

Thanks for the reply Axel. What exactly do you mean with you can declare the same inside the report template? Do you mean to add everything between style= or? Its pretty strange that you need to base64 encode your font family by the way.. :/

Yenthe
on 7/30/15, 9:20 AM

I mean like using . I update my answer to include those tags. That need to be declared as part of your report template. It's rare but it's a solution

Axel Mendoza
on 7/30/15, 9:27 AM

I mean style tag definition. Odoo forum delete the tag style in the previous comment. The answer is ok

Axel Mendoza
on 7/30/15, 9:28 AM

@Axel thanks for the update. I did try the method of adding the CSS within the XML template but that doesn't get rendered either. Not even the color for example, so this makes me believe CSS inside the XML templates does not work?

Yenthe
on 7/30/15, 9:44 AM

Docs said: Useful Remarks Twitter Bootstrap and FontAwesome classes can be used in your report template Local CSS can be put directly in the template Global CSS can be inserted in the main report layout by inheriting its template and inserting your CSS

Axel Mendoza
on 7/30/15, 9:49 AM

@Axel I've tried adding CSS in the latest runbot for simply centering and coloring a H1 in a report and that doesn't even work. Perhaps this never even worked in Odoo? Any ideas?

Yenthe
on 7/30/15, 10:02 AM

I edited my answer with the solution to load css and styles, explaining why did not work before

Axel Mendoza
on 7/30/15, 11:33 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: 7/30/15, 8:06 AM
Seen: 5196 times
Last updated: 8/23/16, 10:37 PM