To protect the integrity of the document and prevent the counterfeiting, it is a good idea to have a watermark in your Odoo reports, such as Sales Quotation, Invoice, Delivery Order, etc.
This Odoo technical development blog is my way to contribute back to the Odoo Community, for all the selfless and great sharing by the community members.
There are 2 methods to add watermark in the background of the Odoo report:
1) Wording such as the Status of the document - eg, Draft, Original, Confidential, etc.
This can be achieve by using the CSS transform property in the Qweb.
<div class="page">
<style>
.watermark {
position: absolute;
opacity:0.2;
font-size:100px;
width:50%;
text-align:center;
z-index:99;
border: 2px solid black;
-webkit-transform: rotate(-30deg);
}
</style>
</div>
<div class="watermark" style="top: 600px; right: 230px;"> <span t-field="o.status"/><br/> </div>
Click "Like" at the bottom of this blog, to motivate us to continue sharing more Odoo tips.
2) Image such as the company logo.
This can be achieve by using the OCA module
note 1: This will add watermark to all the documents in Odoo.
note 2: Wkhtmltopdf version must be 0.12.5 or above.
You may want to enhance the module to enable the upload of the watermark pdf per company (in multi-companies scenario).
These are 2 websites that are handy to create a nice watermark in pdf.
You may want to enhance the report_qweb_pdf_watermark module, report.py to use your uploaded watermark pdf.
@api.model
def _run_wkhtmltopdf(self, bodies, header=None, footer=None,
landscape=False, specific_paperformat_args=None,
set_viewport_size=False):
result = super(Report, self)._run_wkhtmltopdf(
bodies, header=header, footer=footer, landscape=landscape,
specific_paperformat_args=specific_paperformat_args,
set_viewport_size=set_viewport_size)
docids = self.env.context.get('res_ids', False)
watermark = None
company = self.env['res.company'].browse(self.env.user.company_id.id)
# if self.pdf_watermark:
# watermark = b64decode(self.pdf_watermark)
if company.upload_image:
watermark = b64decode(company.upload_image)
elif docids:
watermark = tools.safe_eval(
self.pdf_watermark_expression or 'None',
dict(env=self.env, docs=self.env[self.model].browse(docids)),
)
if watermark:
watermark = b64decode(watermark)
if not watermark:
return result
Click "Like" at the bottom of this blog, to motivate us to continue sharing more Odoo tips.
Hi,
In the above method water mark print only in one page , can you give example water mark to print all page...