跳至內容
Odoo 選單
  • 登入
  • 免費試用
  • 應用程式
    財政
    • 會計
    • 發票
    • 開支報銷
    • 試算表 (BI)
    • 文件管理
    • 電子簽名
    銷售
    • 客戶關係
    • 銷售
    • POS 銷售點管理 - 零售
    • POS 銷售點管理 - 餐廳
    • 訂閱
    • 租賃
    網站
    • 網站製作
    • 電子商務
    • 網誌
    • 討論區
    • 線上客服
    • 網上學習
    供應鏈
    • 庫存
    • 製造管理
    • 產品生命周期
    • 採購
    • 保養維護
    • 品質管理
    人力資源
    • 員工管理
    • 招聘
    • 休假
    • 工作表現評核
    • 內部推薦
    • 車隊管理
    市場推廣
    • 社交媒體推廣
    • 電郵推廣
    • 短訊營銷
    • 活動
    • 自動化推廣
    • 網上調查
    服務
    • 專案管理
    • 工時管理
    • 外勤服務管理
    • 技術支援
    • 工作規劃
    • 預約管理
    生產力
    • 聊天
    • 批核
    • 物聯網
    • VoIP
    • 知識庫
    • WhatsApp
    第三方應用程式 Odoo Studio Odoo 雲端平台
  • 行業
    零售
    • 書店
    • 服裝店
    • 家具店
    • 食品雜貨店
    • 五金店
    • 玩具店
    餐飲及款待
    • 酒吧及酒館
    • 餐廳
    • 快餐
    • 賓館
    • 飲品分銷商
    • 酒店
    房地產
    • 地產代理公司
    • 建築師事務所
    • 建造業
    • 物業管理
    • 園藝
    • 業主聯會
    顧問服務
    • 會計公司
    • Odoo 合作夥伴
    • 市場推廣公司
    • 律師事務所
    • 人才招募
    • 審計及認證
    製造管理
    • 紡織
    • 金屬
    • 家具
    • 食品
    • 啤酒廠
    • 企業禮品
    保健與健身
    • 運動俱樂部
    • 眼鏡店
    • 健身中心
    • 健康從業人員
    • 藥房
    • 髮型屋
    技術行業
    • 雜工
    • IT 硬體與支援
    • 太陽能系統
    • 鞋匠
    • 清潔服務
    • 暖通空調服務
    其他
    • 非牟利組織
    • 環境保護機構
    • 廣告板租賃
    • 攝影服務
    • 自行車租賃
    • 軟體經銷商
    瀏覽所有行業
  • 社群
    學習
    • 教學影片
    • 使用說明
    • 認證
    • 培訓
    • 網誌
    • Podcast
    增強教學效能
    • 教育計劃
    • Scale Up! 商業遊戲
    • 到訪 Odoo
    取得軟件
    • 下載
    • 版本對照表
    • 版本說明
    合作
    • GitHub
    • 討論區
    • 活動
    • 翻譯
    • 成為合作夥伴
    • 合作夥伴服務
    • 登記你的會計服務公司
    獲取服務相關資料
    • 尋找合作夥伴
    • 尋找會計服務
    • 預約顧問諮詢
    • 安裝及推行服務
    • 客戶案例
    • 支援
    • 軟件升級
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    預約示範
  • 定價
  • 技術支援

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客戶關係
  • e-Commerce
  • 會計
  • 庫存
  • PoS
  • 專案管理
  • MRP
All apps
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
支援

How to add custom fonts to QWeb reports?

訂閱

此帖文有活動時,接收通知

此問題已被標幟
qwebreportingfontsodoo8.0
6 回覆
70079 瀏覽次數
頭像
Yenthe Van Ginneken (Mainframe Monkey)

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

7
頭像
捨棄
Deepa Venkatesh

@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

頭像
Axel Mendoza
最佳答案

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>

8
頭像
捨棄
Yenthe Van Ginneken (Mainframe Monkey)
作者

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.. :/

Axel Mendoza

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

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

Yenthe Van Ginneken (Mainframe Monkey)
作者

@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?

Axel Mendoza

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

Yenthe Van Ginneken (Mainframe Monkey)
作者

@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?

Axel Mendoza

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

頭像
Cyril
最佳答案

Hello

In odoo v10, it seems to be super easy... That's what we did with google font Roboto :

- Inherit css with google :

<xpath expr="." position="inside">
    <link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed" rel="stylesheet"/>
</xpath>

- Inherit the reports with font-family :

<xpath expr="//div[@class='page']" position="attributes">
    <attribute name="style">font-family: 'Roboto', sans-serif;</attribute>
</xpath>

- Inherit the header and footer with font-family :

<xpath expr="//div[@class='footer']" position="replace">
    <div class="footer" style="font-family: 'Roboto Condensed', sans-serif;">
...

It works with wkhtmltopdf 0.12.1


7
頭像
捨棄
Ermin Trevisan

Can you please explain which css file should be inherited with google? Could you provide an example of the complete xml file?

頭像
Jose David Moreno Hernandez
最佳答案

In case someone is looking for an Odoo v12 approach:

If you just need your custom font to be rendered in your HTML reports. In your custom css file you can:

body{    
    font-family: 'Montserrat', sans-serif;
}

And then, in your assets.xml file you could inherit the report_assets_common in this way:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
        <template id="report_assets_common" name="Technical Service Assets Reports" inherit_id="web.report_assets_common">
            <xpath expr="//link[last()]" position="after">
                <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"/> /*Here your chosen Google Font or any other*/
                <link rel="stylesheet" href="your_custom_module/static/src/css/report_styles.css"/> /*This is your custom css file*/
            </xpath>
        </template>
</odoo>

Finally add both files if not already there in your __manifest__.py:

'data': [
    'views/assets.xml',
],
'css': [
    'static/src/css/report_styles.css',
],

But this doesn't work that easy with pdf rendering. In that other case, following the @Cyril concept:

 This is for PDF printing reports:


Same as before, append your new fonts to the assets:

<?xml version="1.0" encoding="utf-8" ?>
<odoo>        
    <template id="report_assets_common" name="Technical Service Assets Reports" inherit_id="web.report_assets_common">           
        <xpath expr="//link[last()]" position="after">                 
            <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet"/> /*Here your chosen Google Font or any other*/                 
            <link rel="stylesheet" href="your_custom_module/static/src/css/report_styles.css"/> /*This is your custom css file*/            
        </xpath>         
    </template>
</odoo>

You could inherit your chosen layout, in this case I'll take the external_layout_standard, and assign the styles to those part of the template you want to be affected. I'll change everything, so I'll select the header, article and the footer. Don't forget to appent to the __manifest__.py and upgrade your module after all.

<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <data>
        <template id="external_layout_standard" inherit_id="web.external_layout_standard">           
            <xpath expr="//div[@class='header']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath>
            <xpath expr="//div[@class='article']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath> 
            <xpath expr="//div[@class='footer']" position="attributes">
                <attribute name="style">font-family: 'Montserrat', sans-serif;</attribute>
            </xpath>
        </template>
    </data>
</odoo>
3
頭像
捨棄
Fady Noor Ilmi Lubis

thank you for making it clear for the PDF

頭像
EasyPME
最佳答案

Here is the complete xml for inheriting css :

<template id="my_module.report_assets_common" name="my_module report assets common" inherit_id="report.assets_common">
    <xpath expr="." position="inside">
        <link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed" rel="stylesheet"/>
    </xpath>
</template>
2
頭像
捨棄
頭像
GabrielLuke
最佳答案

Generically, you can use a custom font using  @font-face  in your CSS. Here’s a very basic example:
@font-face {
font-family: 'YourFontName'; /*a name to be used later*/
src: url('http://domain.com/fonts/font.ttf'); /*URL to font*/
}

Then, trivially, to use the font on a specific element:

`.classname {`
`    font-family: 'YourFontName';`
`}`
.classname {
    font-family: 'YourFontName';
}
``
(.classname is your selector).

Note that certain font-formats don’t work on all browsers; you can use some generator to avoid too much effort converting.

You can find a nice set of free web-fonts provided by Google Fonts (I can’t insert more than 1 link so you can go to Google fonts) (also has auto-generated CSS  @font-face  rules, so you don’t have to write your own).

while also preventing people from having free access to download the font, if possible

Nope, it isn’t possible to style your text with a custom font embedded via CSS, while preventing people from downloading it. You need to use images, Flash, or the HTML5 Canvas, all of which aren’t very practical.

I hope that helped!

0
頭像
捨棄
頭像
Atharva System
最佳答案

You can try check this module. https://apps.odoo.com/apps/modules/15.0/advanced_report_templates/

0
頭像
捨棄
喜歡這則討論?不要只閱讀,加入發表意見吧!

今天就建立帳戶,享受獨家功能,與我們精彩的社群互動!

註冊
相關帖文 回覆 瀏覽次數 活動
How to change fonts in QWeb Reports v11.0
qweb reporting fonts v11.0
頭像
頭像
頭像
頭像
4
4月 18
17507
How to check checkbox state in QWeb report? 已解決
qweb reporting checkbox odoo8.0
頭像
頭像
1
3月 15
13683
How can I display all tasks (including completed ones) in a QWeb report in Odoo?
qweb reporting
頭像
頭像
2
9月 24
3054
Odoo 8 Reporting : Change default "Total" label 已解決
reporting odoo8.0
頭像
頭像
1
3月 22
8199
How do i create report in Qweb? 已解決
qweb reporting
頭像
頭像
頭像
頭像
頭像
5
8月 19
47548
社群
  • 教學影片
  • 使用說明
  • 討論區
開源
  • 下載
  • GitHub
  • Runbot 測試環境
  • 翻譯
服務
  • odoo.sh 網頁寄存
  • 支援
  • 升級
  • 自訂功能開發
  • 教育及培訓
  • 尋找會計服務
  • 尋找合作夥伴
  • 成為合作夥伴
關於我們
  • 關於 Odoo 公司
  • 品牌資產
  • 聯絡我們
  • 招聘
  • 活動
  • Podcast
  • 網誌
  • 客戶
  • 法律 • 私隱政策
  • 安全性
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo 是一套開放源碼的商業管理系統,涵蓋你公司全部的營運需要,包括客戶關係管理(CRM)、電子商務、會計、庫存管理、POS(銷售點管理)、專案管理等應用程式。

Odoo 的獨特價值是非常簡單易用,同時將不同應用程式完美整合。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now