Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Custom qweb report with css not working

Naroči se

Get notified when there's activity on this post

This question has been flagged
pdfqwebreportv9odooV9
2 Odgovori
25442 Prikazi
Avatar
Emanuel Cino

0 down vote \favorite

I'm creating a new report on Odoo 9 which uses css styles in order to position text over a background image. The image is in background and occupies the full A4 page without any margins.

In html, it's working fine. However, when I print the report to PDF, I have blank margins at left and right, and the text goes below the background image. It seems that the CSS rules are not applied. Do you find any solution for making it working in PDF?

Here is my report:

<template id="sub_proposal">
<style type="text/css">
.container {
padding: 0mm;
}
#sponsor-ref {
position: absolute;
top: 84mm;
left: 45mm;
}
#form_image {
position: absolute;
top: 0mm;
left: 0mm;
width: 210mm;
height: 297mm;
}
#form_image img {
max-width: 100%;
max-height: 100%;
margin: auto;
}
</style>
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
<div id="form_image">
<span t-field="o.sub_proposal_form" t-field-options='{"widget": "image"}'/>
</div>
<span id="sponsor-ref" t-field="o.ref"/>
</div>
</t>
</t>
</template>
2
Avatar
Opusti
Avatar
Travis Waelbroeck
Best Answer

The style tag and contents must be set within the <div class="page"> element.

I don't have any documentation, only from experience.
\Link to same question on Stack Overflow.

5
Avatar
Opusti
Emanuel Cino
Avtor

Thanks, this resolved my issue! Somehow, css style in the head section is ignored in PDF.

Emanuel Cino
Avtor

As well, it seems less optimized to load the style at each new page, so I wonder if there would be a solution allowing to declare only once the style.

Avatar
Chandran N Nepolean
Best Answer

Hi cino,

<template id="style_plain">

  <style type="text/css">

   .address {

    background-color:yellow!important;

                                           color:green!important;

                                 }

  </style>

 </template>

  <template id="html_container_plain">

   <t t-call="report.html_container">

    <t t-raw="0" />

   </t>

   <xpath expr="//head" position="inside">

    <t t-call="plain_reports.style_plain" />

   </xpath>

  </template>

This sample should work. Please modify according to your needs. your code missed xpath header section that is important because it will add your css in header then only your pdf will take those styles



Thanks

Chandran Nepolean

1
Avatar
Opusti
Emanuel Cino
Avtor

Sorry but it does produce the exact same result as I mentioned. It seems that PDF generation does not take into account css style in the head section because answer from Travis who proposes to put the style inside the page does make it work.

Chandran N Nepolean

Have you created two templates sepeartely one for css and other for design?

Chandran N Nepolean

if you followed this example.. please past your code here..it will be easy to debug

Emanuel Cino
Avtor

Yes I separated the templates. Here was my code :

<template id="style">

<!-- Add report style -->

<style type="text/css">

.container {

padding: 0mm;

}

#sponsor-ref {

position: absolute;

top: 84mm;

left: 45mm;

}

#form_image {

position: absolute;

top: 0mm;

left: 0mm;

width: 210mm;

height: 297mm;

}

#form_image img {

max-width: 100%;

max-height: 100%;

margin: auto;

}

</style>

</template>

<template id="html_container">

<t t-call="report.html_container">

<t t-raw="0"/>

</t>

<xpath expr="//head" position="inside">

<t t-call="report_custom.style"/>

</xpath>

</template>

<template id="sub_proposal">

<t t-call="report_custom.html_container">

<t t-foreach="docs" t-as="o">

<div class="page">

<div id="form_image">

<span t-field="o.sub_proposal_form" t-field-options='{"widget": "image"}'/>

</div>

<t t-if="o.lang in ('en_US', 'it_IT')">

<span id="sponsor-ref" t-field="o.ref"/>

</t>

<t t-if="o.lang in ('fr_CH', 'de_DE')">

<span id="sponsor-ref" t-field="o.ref" style="top: 88mm;"/>

</t>

</div>

</t>

</t>

</template>

Chandran N Nepolean

Please try this

<template id="style">

<!-- Add report style -->

<style type="text/css">

.container {

padding: 0mm;

}

#sponsor-ref {

position: absolute;

top: 84mm;

left: 45mm;

}

#form_image {

position: absolute;

top: 0mm;

left: 0mm;

width: 210mm;

height: 297mm;

}

#form_image img {

max-width: 100%;

max-height: 100%;

margin: auto;

}

</style>

</template>

<template id="sub_proposal">

<xpath expr="//head" position="inside">

<t t-call="report_custom.style"/>

</xpath>

<t t-call="report_custom.html_container">

<t t-foreach="docs" t-as="o">

<div class="page">

<div id="form_image">

<span t-field="o.sub_proposal_form" t-field-options='{"widget": "image"}'/>

</div>

<t t-if="o.lang in ('en_US', 'it_IT')">

<span id="sponsor-ref" t-field="o.ref"/>

</t>

<t t-if="o.lang in ('fr_CH', 'de_DE')">

<span id="sponsor-ref" t-field="o.ref" style="top: 88mm;"/>

</t>

</div>

</t>

</t>

</template>

Chandran N Nepolean

If you still could not got working..Please follow below link

https://github.com/suhe/odoo/blob/149a84c2472a0b17c79f6fc4f299ee5daae70833/addons/sample_qweb_report/report/product_template_report_templates.xml

it will show you how to deal with css and report

Emanuel Cino
Avtor

Sorry, still not. If I change

<xpath expr="//head" position="inside">

<t t-call="report_custom.style"/>

</xpath>

by just calling the style

<t t-call="report_custom.style"/>

after <div class="page">, it works. Must be PDF limitations as your solution works in HTML but not in PDF.

Chandran N Nepolean

Hi Cino,

Please give last try this one..

so change path here <xpath expr="//div[@class='page']" position="after">

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Conditional column on table
pdf qweb report
Avatar
0
maj 24
2743
Change font in QWeb template
pdf qweb report
Avatar
Avatar
Avatar
2
maj 24
4980
Sale Order PDF Report Solved
pdf qweb report
Avatar
Avatar
Avatar
Avatar
3
feb. 24
4322
[ODOO 15] PDF in Qweb Report
pdf qweb report
Avatar
Avatar
Avatar
2
nov. 22
6965
Invoice on basic layout
pdf invoice qweb report
Avatar
0
apr. 24
2700
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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