使用以下代码在输出pdf上显示阿拉伯语错误:
template = get_template(template_src)
context = Context(context_dict)
html = template.render(context)
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(
html.encode(pdf_encoding)), result, encoding=pdf_encoding) # pdf_encoding = 'utf-8'
在模板中我设置了charset和fonts:
<meta http-equiv="content-type" content="text/html; charset=utf-8">
@font-face {
font-family: AmiriRegular;
src: url(/usr/share/fonts/opentype/fonts-hosny-amiri/amiri-regular.ttf);
}
body { font-family: AmiriRegular; }
快照中的阿拉伯文本应该是:
ياسر حسن
答案 0 :(得分:0)
我认为一种解决方案是手动传递这些阿拉伯文本,然后使用以下两个库对它们进行整形:
import arabic_reshaper
from bidi.algorithm import get_display
reshaped_text = arabic_reshaper.reshape('your desired text in arabic')
bidi_text = get_display(reshaped_text)