Python Reportlab拉丁字符编码
ReportLab中,您将如何管理某些拉丁字符(č,¶,Ž,Š,°)?尝试了各种类型的UTF-8编码,但没有运气。它显示为不可读的数据流。
谁能帮忙?另外,我多次更改字体,但也没有成功。
这是我遇到问题的PDF的一部分 -
data2 = [[ Paragraph(cell, styleN) if cell.isascii() and cell.isprintable() else Paragraph(cell.encode('utf-8'), styleN) for cell in row] for row in array]
t = Table(data2, colWidths=[None] + [2.2*inch] + [1.3 * inch]*int(len(json.loads(request.POST['kolone'])) - 2 ), rowHeights= [None] + [0.5*inch] + [None] * int(len(array) -2), repeatRows=1)
t.setStyle(TableStyle([('TEXTCOLOR',(1,1),(-2,-2), "black"), ('FONTSIZE', (0,0),(-1,-1), 9), ('BOX', (0,0), (-1,0), 0.25, 'black'), ('PADDING', (0,0),(-1,-1), 2), ('VALIGN', (0,0), (-1,-1), 'TOP')]))
如您所见,我尝试界定所有具有“特殊字符”的记录并编码它们。
How would you manage certain latin characters (č, ć, ž, š, đ) in reportlab? Tried various types of UTF-8 encoding, but without luck. It displays as unreadable streams of data.
Can anyone help? Also, I changed fonts multiple times, but also without success.
This is part of PDF where I'm getting problem -
and this is my part of code (beside that, OpenSans font is set that supports letters like š, ć, č, ž, đ):
data2 = [[ Paragraph(cell, styleN) if cell.isascii() and cell.isprintable() else Paragraph(cell.encode('utf-8'), styleN) for cell in row] for row in array]
t = Table(data2, colWidths=[None] + [2.2*inch] + [1.3 * inch]*int(len(json.loads(request.POST['kolone'])) - 2 ), rowHeights= [None] + [0.5*inch] + [None] * int(len(array) -2), repeatRows=1)
t.setStyle(TableStyle([('TEXTCOLOR',(1,1),(-2,-2), "black"), ('FONTSIZE', (0,0),(-1,-1), 9), ('BOX', (0,0), (-1,0), 0.25, 'black'), ('PADDING', (0,0),(-1,-1), 2), ('VALIGN', (0,0), (-1,-1), 'TOP')]))
As you can see, I tried to delimit all records that have "special character" and encode them.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论