26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
"""wkhtmltopdf 命令行猴子补丁。
|
|
|
|
Odoo 18 base 模块在 `ir.actions_report._build_wkhtmltopdf_args` 里
|
|
显式传入 `['--disable-local-file-access']`(见 odoo/addons/base/models/ir_actions_report.py 第 304 行),
|
|
导致 wkhtmltopdf 无法读取本地文件——既包括 @font-face 的 file://,也包括 Qt 从 `C:\Windows\Fonts`
|
|
读取系统字体(@font-face 用注册名找字体也走不到文件)。结果是 PDF 中文渲染成豆腐方框。
|
|
|
|
本补丁把 `--disable-local-file-access` 换成 `--enable-local-file-access`,让 wkhtmltopdf 能读到
|
|
中文字体文件,从而正确渲染 PDF 中文。
|
|
"""
|
|
|
|
from odoo.addons.base.models import ir_actions_report
|
|
|
|
_original_build_args = ir_actions_report.IrActionsReport._build_wkhtmltopdf_args
|
|
|
|
|
|
def _patched_build_wkhtmltopdf_args(self, *args, **kwargs):
|
|
cmd = _original_build_args(self, *args, **kwargs)
|
|
# 把 --disable-local-file-access 替换成 --enable-local-file-access
|
|
cmd = [a for a in cmd if a != '--disable-local-file-access']
|
|
if '--enable-local-file-access' not in cmd:
|
|
cmd.append('--enable-local-file-access')
|
|
return cmd
|
|
|
|
|
|
ir_actions_report.IrActionsReport._build_wkhtmltopdf_args = _patched_build_wkhtmltopdf_args |