python - 如何从 Python 代码生成 PDF 报告。奥杜 16

标签 python pdf odoo report

我有一个自定义向导,其中包含以下字段:“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/

相关文章:

php - 如何使用 Google API 翻译 .PDF 文件?

python - 在 OpenERP 中如何将继承对象视为子类?

python - 检查表格上的产品可用性 - 返回 stock.quants - Odoo v8

python - 有没有办法获取 'own' 或 'get priority over' linux 中外部进程的 stdin 文件描述符?

python - 尝试将文件作为存档打开,否则作为普通文件读取

java - 无法使用java去除pdf中的页面线

javascript - 根据条件为 Odoo10 中的复选框添加颜色

python - 定时任务 : Using Python and sending email attachment

python - 无法解压缩使用 zipfile (Python) 构建的存档

c++ - QPdfWriter 和页面大小