【问题标题】:Thai Font in Django PDFDjango PDF中的泰语字体
【发布时间】: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

当我跑步时,它很丑。像这样

https://i.stack.imgur.com/e0OUg.png

【问题讨论】:

  • 我怀疑这是 xhtml2pdf 的问题,而不是 django 本身的问题。所以你可能在那个库中比在 Django 中更成功。其次,将可变参数作为默认参数传递是个坏主意:docs.python-guide.org/writing/gotchas

标签: python xhtml2pdf


【解决方案1】:

在 invoice.html 中添加泰语字体

<style type="text/css">

            @font-face {
            font-family: "THSarabunNew";
            src: url("/home/pinsz/THSarabunNew.ttf");
            }

            body {
                font-weight: 200;
                font-size: 18px;
                font-family: "THSarabunNew";
            }
</style>

泰文示例:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    相关资源
    最近更新 更多