Django PDF中的泰语字体

时间:2018-08-26 13:52:11

标签: python xhtml2pdf

我通过django生成了pdf文件,但不适用于Thai Font

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

1 个答案:

答案 0 :(得分:0)

要在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>

泰文示例: enter image description here