为什么标题中的特定DIV在Odoo 13中的PDF中重叠了页面?
我正在Odoo 13 Enterprise中进行定制的PDF报告。我必须在报告的每个页面的左边缘中添加垂直文本。因此,我需要将该垂直文本放在标题中。
为此,首先,我创建了自己的纸面形式:
<record id="my_paperformat_euro" model="report.paperformat">
<field name="name">My European A4</field>
<field name="default" eval="False" />
<field name="format">A4</field>
<field name="orientation">Portrait</field>
<field name="margin_top">35</field>
<field name="margin_bottom">18</field>
<field name="margin_left">0</field>
<field name="margin_right">0</field>
<field name="header_line" eval="False" />
<field name="header_spacing">30</field>
</record>
然后我修改了调用报告应用程序以应用我的纸张的proce的操作:
<record id="sale.action_report_saleorder" model="ir.actions.report">
<field name="paperformat_id" ref="my_module.my_paperformat_euro"/>
</record>
我这样做是因为如果我想写入“保证金”,则纸张formats不能有任何保证金,以免隐藏我在那里写的东西。当然,然后我在报告的所有主要元素上应用了一个左侧边距。 div
将保证金文本互联面以负面的绝对位置对其进行了对抗。
然后,我在报告标题中的保证金文本中添加了div
:为此,我做了自己的external_layout_standard
,然后我继承了external_layout
template为了调用它(我只在此处粘贴相关代码):
<template id="external_layout_standard">
<!-- HEADER -->
<div t-attf-class="header o_company_#{company.id}_layout o_my_special_page" t-att-style="report_header_style">
...
<div class="o_my_margin text-muted">
<span t-if="company.vat">CIF: <span t-field="company.vat"/></span>
<span t-if="company.vat and company.company_registry"> | </span>
<span t-if="company.company_registry" t-field="company.company_registry"/>
</div>
</div>
...
<!-- BODY -->
...
<!-- FOOTER -->
...
</template>
我在正确加载的CSS文件中定义了类:
div.o_my_special_page {
margin-left: 15mm !important;
margin-right: 15mm !important;
}
div.o_my_margin {
position: absolute;
top: 85mm;
left: -65mm;
z-index: -50147483647;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
font-size: 8pt;
float: left;
width: 150mm;
height: 15mm;
background: red;
}
现在,问题。此代码与WKHTMLTOPDF 0.12.1完美搭配。但是,安装了WKHTMLTOPDF 0.12.5,我得到了:
如您所见,似乎将白色div
放在我的保证金的正确部分<代码> div (红色一个),此白色div
与报告内容的其余内容重叠。但是,如果我以HTML模式打印报告或使用WKHTMLTOPDF 0.12.1安装(如上所述),则不会发生这种情况。
有人知道为什么吗?有什么想法可以解决这个问题或替代我的目的?
I am making a customized PDF report in Odoo 13 Enterprise. I have to add a vertical text in the left margin of each page of the report. So I need to put that vertical text in the header.
To do that, first I created my own paperformat:
<record id="my_paperformat_euro" model="report.paperformat">
<field name="name">My European A4</field>
<field name="default" eval="False" />
<field name="format">A4</field>
<field name="orientation">Portrait</field>
<field name="margin_top">35</field>
<field name="margin_bottom">18</field>
<field name="margin_left">0</field>
<field name="margin_right">0</field>
<field name="header_line" eval="False" />
<field name="header_spacing">30</field>
</record>
Then I modified the report action which calls the report to apply my paperformat:
<record id="sale.action_report_saleorder" model="ir.actions.report">
<field name="paperformat_id" ref="my_module.my_paperformat_euro"/>
</record>
I did this because if I want to write in "margins", the paperformat cannot have any margin in order not to hide what I write there. Of course then I applied a left margin to all the main elements of the report. The div
cointaining the margin text counteracted it with a negative absolute position.
Then I added the div
with the margin text in the report header: to do that I did my own external_layout_standard
and then I inherited the external_layout
template in order to call it (I only paste the relevant code here):
<template id="external_layout_standard">
<!-- HEADER -->
<div t-attf-class="header o_company_#{company.id}_layout o_my_special_page" t-att-style="report_header_style">
...
<div class="o_my_margin text-muted">
<span t-if="company.vat">CIF: <span t-field="company.vat"/></span>
<span t-if="company.vat and company.company_registry"> | </span>
<span t-if="company.company_registry" t-field="company.company_registry"/>
</div>
</div>
...
<!-- BODY -->
...
<!-- FOOTER -->
...
</template>
I defined the classes in a CSS file which is correctly loaded:
div.o_my_special_page {
margin-left: 15mm !important;
margin-right: 15mm !important;
}
div.o_my_margin {
position: absolute;
top: 85mm;
left: -65mm;
z-index: -50147483647;
transform: rotate(-90deg);
-webkit-transform: rotate(-90deg);
font-size: 8pt;
float: left;
width: 150mm;
height: 15mm;
background: red;
}
Now, the problem. This code works perfectly with Wkhtmltopdf 0.12.1. But, with Wkhtmltopdf 0.12.5 installed, I get this:
As you can see, it seems as if a white div
was put on the right part of my margin div
(the red one), and this white div
was overlaping the rest of the report content. However, this does not happen if I print the report in HTML mode or if I print it with Wkhtmltopdf 0.12.1 installed (as I've mentioned above).
Does anyone know why? Any ideas to fix this or an alternative one to achieve my purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我找到了自己问题的答案。如果任何人与我处于相同的情况,那么关键是将以下样式添加到您的CSS文件中:
避免标题重叠报告主体。我在模块
report_qweb_pdf_watermark
中找到了这一行,顺便说一句,它是一个非常有趣的应用程序,可以在PDF报告中添加水印。Finally I've found the answer to my own question. If anyone is in the same situation as I was, the key is to add the following style to your CSS file:
That avoids header to overlap report body. I've found this line in the module
report_qweb_pdf_watermark
, which by the way it is a very interesting app to add watermarks to PDF reports.