How to Generate Pdf Report from Python Code. Odoo 16
I Have a Custom Wizard with Fields: "File_Name"(Char), "Model_Id"(Active Model), "Content_Report"(Html). I Added a Print Button in This Wizard. When I Click on...
I have a custom wizard with fields : "file_name"(Char), "model_id"(active model), "content_report"(html) . I added a print button in this wizard . When I click on this button I want to generate reporte with name = "file_name" and content of report = "content_report" , without using a report template. Only with python code?
How can I do it? Any help please?
Thanks.
1 Answer
You can use _run_wkhtmltopdf function used to print the qweb reports.
Example:
def render_html(self):
self.ensure_one()
action_report = self.env['ir.actions.report']
pdf_content = action_report._run_wkhtmltopdf(
[self.content_report],
report_ref=None,
header=header,
footer=footer,
landscape=False,
specific_paperformat_args=specific_paperformat_args,
set_viewport_size=False,
)
self.update({'file_content': base64.b64encode(pdf_content)})
Your HTML should be enclosed in main tag