[Answer]-ReportLab Django Not Rendering Chinese Characters

1👍

Solved it. Turns out in your ParagraphStyle it needs to be fontName=”Arial” not font=”Arial” but I did learn some other tricks of getting it to work in other ways below.

styles.add(ParagraphStyle(name='Address', fontName='Arial')

After doing some digging I’ve learned a few things that I hope helps someone else in this situation. When you add the tags inside of your Paragraph around the Unicode text and set it explicitly to a font it will work.

elements.append(Paragraph(u'<font name="Arial">6905\u897f\u963f\u79d1\u8857\uff0c\u5927\u53a6\uff03\u5927</font>', styles['Address']))

This fixes the problem at least for Paragraphs with various fonts.
Again this code will work.

0👍

Choose the fonts that supports Chinese characters.

In Ubuntu, I choose “AR PL UMing CN” for example.

My code snippets:

# -*- coding: utf-8 -*-
...
pdfmetrics.registerFont(TTFont('AR PL UMing CN', 'uming.ttc'))
styles = getSampleStyleSheet()

...
styles.add(ParagraphStyle(name='Chinese', fontName='AR PL UMing CN',    fontSize=20))

elements=[]
elements.append(Paragraph("成”, styles['Chinese']))
doc.build(elements)
...

I can even change to Chinese editor and type in the character straight off. Hope this helps.

👤way

Leave a comment