This question has been flagged
3 Replies
14787 Views

Hello,

the goal is to generate a pdf with complex raw html data:

  • Model has a simple not-sanitized html field

  • That field might be edited by user through the Odoo website editor. In such a way its content might be complex and might have bootstrap classes such as 'col-lg-6', etc.

  • The pdf is generated using QWeb templates.

As a result, when printed not full content of containers is reflected in pdf. In particular, some columns are outside the page (not visible). For example, if to add the snippet '3 columns' or 'image + text column', only the first column is printed.

The question is what is a safe method to reflect the most content of html field in QWeb template.

Already tried:

  • t-esc, t-raw, t-field

  • wrapping in containers and in different html tags

  • provide css styles, including assigning different 'display' param

  • t-set full_width, even landscape page format

Please find a sample of source code below.

Field declaration

    description =fields.Html(string="Description", sanitize=False)

Reports

    <template id="report_item_document">
        <t t-call="web.external_layout">
            <div class="page">
                <div class="oe_structure"/>
                <h2><span t-field="doc.name"/></h2>
                <div>
                    <t t-raw="doc.description"/>
                </div>
                <div class="oe_structure"/>
            </div>
        </t>
    </template>

    <template id="report_item">
        <t t-call="web.html_container">
            <t t-foreach="docs" t-as="doc">
                <t t-call="my_module.report_item_document"/>
            </t>
        </t>
    </template>

Avatar
Discard
Author

Hi, Sehrish. I do not need to learn Odoo, I do need to print pdf with website edited html. Search by 'qweb' returns only very standard questions which are of no use for me

Author Best Answer

For those who faced a similar issue: what we have revealed:

The only viable way seems to redefine all styles used in website in qweb to fit the page or/and replace classes before printing. This taks is a sort of drastic job since assumes a lot of experimenting and coding. Moreover, some styles are just difficult to show in a printing version (e.g. video links, slider effects, etc.). Thus, this approach is not promising.

The better is to initially restrict users in using building blocks (snippets) to fit a printing version. Similar job is done in the mass_mailing module where all blocks are table-wrapped. Although it also implies quite much of coding to prepare a builder and snippets, it is much safer.

The last found way is to use browser printing version of a page. In that case a lot of excess elements are added, and there is a need to work with external to Odoo features.

Avatar
Discard

Hi, I am facing similar type of issue, can you check it out, please? https://www.odoo.com/forum/help-1/question/how-to-apply-flex-style-to-report-163753