python – 报告实验室无法处理希伯来语(unicode)
作者:互联网
我试图从以下python编程生成pdf但生成的输出不能正确显示希伯来字母
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
def hello(c):
c.drawString(100,100, "מה שלומך")
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
解决方法:
这段代码(见下文)有效!您需要做的就是将ArialHB.ttf(或任何其他支持希伯来字符的字体)放入site-packages / reportlab / fonts …
所需的输出将位于pdf页面的底部.
# -*- coding: utf-8 -*-
from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('Hebrew', 'ArialHB.ttf'))
def hello(c):
c.setFont("Hebrew", 14)
c.drawString(10,10, u"מה שלומך".encode('utf-8'))
c = canvas.Canvas("hello.pdf")
hello(c)
c.showPage()
c.save()
标签:python,reportlab 来源: https://codeday.me/bug/20190613/1232990.html