【发布时间】:2018-08-26 13:52:10
【问题描述】:
我通过 django 生成 pdf 文件,但它不适用于泰语字体
util.py
from xhtml2pdf import pisa
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None
当我跑步时,它很丑。像这样
【问题讨论】:
-
我怀疑这是 xhtml2pdf 的问题,而不是 django 本身的问题。所以你可能在那个库中比在 Django 中更成功。其次,将可变参数作为默认参数传递是个坏主意:docs.python-guide.org/writing/gotchas