Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
650 Tampilan

Hi everyone,

I'm working on a custom report in Odoo 17, and I've run into an issue with the layout.

I created a new report_paperformat and a custom report template. I removed the default Odoo header (web.external_layout) and footer, but I still have extra white space at the top and bottom of the generated PDF.

Here’s what I’ve already tried:

  • Replaced <t t-call="web.external_layout"> with my own layout using t-foreach="docs".
  • Removed any t-call="web.internal_layout" as well.
  • Defined a new paper format in report_paperformat.xml with margins set to 0.

Despite this, the PDF still includes a blank area at the top and bottom — it seems like the old margins are still applied.

🔧 My paperformat XML:

xml

CopyEdit

<record id="custom_report_paperformat" model="report.paperformat"> <field name="name">Custom Format</field> <field name="default" eval="True"/> <field name="format">A4</field> <field name="margin_top">0</field> <field name="margin_bottom">0</field> <field name="margin_left">0</field> <field name="margin_right">0</field> <field name="header_line" eval="False"/> <field name="orientation">Portrait</field> <field name="page_height">0</field> <field name="page_width">0</field> <field name="dpi">90</field> </record>

❓Question:

How can I completely remove the top and bottom spacing in the report PDF?

Is there a way to force zero margin rendering, or do I need to override something in the QWeb rendering engine or CSS?

Thank you in advance!

Avatar
Buang
Jawaban Terbai

Hi,


This is a common issue when working with custom PDF reports in Odoo. Even after setting margins to 0 and removing the header/footer, white space may still appear. Here's how to solve it completely:


Corrected Paper Format XML:

The issue is likely caused by setting page_height and page_width to 0, which tells wkhtmltopdf to fall back to default A4 size with default margins.

You should explicitly define A4 dimensions in mm:


<record id="custom_report_paperformat" model="report.paperformat">

    <field name="name">Custom Format</field>

    <field name="default" eval="True"/>

    <field name="format">A4</field>

    <field name="margin_top">0</field>

    <field name="margin_bottom">0</field>

    <field name="margin_left">0</field>

    <field name="margin_right">0</field>

    <field name="header_line" eval="False"/>

    <field name="orientation">Portrait</field>

    <field name="page_height">297</field> <!-- A4 height in mm -->

    <field name="page_width">210</field>  <!-- A4 width in mm -->

    <field name="dpi">90</field>

</record>


Attach the Paper Format to the Report

Ensure your custom report uses this paper format:


<record id="your_custom_report_action" model="ir.actions.report">

    <field name="paperformat_id" ref="your_module.custom_report_paperformat"/>

</record>


Hope it helps.


Avatar
Buang
Jawaban Terbai

Defining a custom report and paper format and removing the default web.external_layout is the correct way to remove default Odoo headers/footers and control layout. However, extra white space still appears in the PDF, which is a common issue due to how wkhtmltopdf handles margins, especially when there are conflicts between HTML/CSS and paper format.


✅ 1. Check Report Paper Format Linkage

Make sure your report is correctly linked to the custom paperformat. In your report.xml or report_action record, add:


<record id="action_report_my_custom" model="ir.actions.report">

    <field name="name">My Custom Report</field>

    <field name="report_name">my_module.report_template_id</field>

    <field name="report_type">qweb-pdf</field>

    <field name="paperformat_id" ref="my_module.custom_report_paperformat"/>

</record>

✅ 2. Set All Margins and Page Sizes Correctly

Your paper format XML looks mostly good. Here's a safer version:

<record id="custom_report_paperformat" model="report.paperformat">

    <field name="name">Custom Format</field>

    <field name="format">A4</field>

    <field name="page_width">0</field>

    <field name="page_height">0</field>

    <field name="margin_top">0</field>

    <field name="margin_bottom">0</field>

    <field name="margin_left">0</field>

    <field name="margin_right">0</field>

    <field name="orientation">Portrait</field>

    <field name="header_line" eval="False"/>

    <field name="dpi">90</field>

    <field name="default" eval="False"/>

</record>

👉 Setting both page_height and page_width to 0 tells Odoo to use the standard A4 dimensions as per the format field.

✅ 3. Force CSS Margin Reset in Template

Sometimes, QWeb adds padding/margins via the stylesheet (report.min.css). Add a style override to your template:



<t t-name="my_module.report_template_id">

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

        <t t-set="css">

            <![CDATA[

                @page {

                    margin: 0mm !important;

                }

                body {

                    margin: 0mm !important;

                    padding: 0mm !important;

                }

                .page {

                    margin: 0mm !important;

                    padding: 0mm !important;

                }

            ]]>

        </t>

        <div class="page">

            <!-- your content -->

        </div>

    </t>

</t>

✅ This helps override any default layout styling inside .page, body, or @page.

Avatar
Buang