我有一个自定义向导,其中包含以下字段:“file_name”(Char)、“model_id”(事件模型)、“content_report”(html)。 我在此向导中添加了一个打印按钮。 当我单击此按钮时,我想生成名称 = "file_name"和报告内容 = "content_report"的报告,而不使用报告模板。仅使用 python 代码?
我该怎么做? 请问有什么帮助吗?
谢谢。
最佳答案
您可以使用_run_wkhtmltopdf用于打印 qweb 报告的函数。
示例:
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)})
您的 HTML 应包含在 main
标记中
关于python - 如何从 Python 代码生成 PDF 报告。奥杜 16,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77141451/