Python Reportlab拉丁字符编码

发布于 2025-02-04 07:32:56 字数 870 浏览 2 评论 0原文

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 -

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文