問題
用reportlab生成pdf文件,碰到中文就會變成黑色的小方塊,如下圖。

中文變成了黑色方塊
解決方法
1.下載中文字體SimSun.ttf
2.把下載下來的字體放到/Library/Python/2.7/site-packages/reportlab/fonts文件夾下。(文件夾根據(jù)自己安裝的reportlab的路徑來)
3.注冊字體并使用
from reportlab.platypus import SimpleDocTemplate, Image, Paragraph
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('SimSun', 'SimSun.ttf')) #注冊字體
styles = getSampleStyleSheet()
styles.add(ParagraphStyle(fontName='SimSun', name='Song', leading=20, fontSize=12)) #自己增加新注冊的字體
Paragraph(describe, styles['Song']), #使用新字體

中文顯示正常
還有文字換行問題,暫時用了下面的方式
Paragraph(u'<br/>%s<br/>' % describe, styles['Song'])
參考:
https://stackoverflow.com/questions/30328945/setfont-in-reportlab-django