我一直在我的reportlab生成的pdf中使用亚洲字体(简体中文/繁体中文,日文和韩文),暂时没有使用。但是最近我们决定启用这样的加密选项:
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.cidfonts import UnicodeCIDFont
pdfmetrics.registerFont(UnicodeCIDFont("STSong-Light"))
enc = pdfencrypt.StandardEncryption(
"", canPrint=1, canModify=0, canCopy=0, canAnnotate=0
)
self._Report = SimpleDocTemplate(
save_file,
topmargin=0.75*inch, bottommargin=0.75*inch,
rightmargin=0.70*inch, leftmargin=0.70*inch,
showBoundary=0,
author="xxx",
title="xxx",
subject=xxx",
encrypt=enc
)
对于非亚洲语言,加密按预期工作。当我们使用加密的亚洲字体时,adobe阅读器无法读取pdf。例如,简体中文我们从Adobe Reader中找到“找不到字体”STSong-Light“错误。
任何人都有任何想法,加密是什么打破了不能使这项工作?
答案 0 :(得分:0)
我遇到了同样的问题。这可能无法解决您的问题。
但是,如果我将其指定为日语,
你可以通过安装TTFont
来解决它(在这个例子中它是IPA哥特式),
并设置字体。
因此,通过安装其他语言字体,您可以解决问题
这不酷。
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter,A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
fontname = 'IPA Gothic'
pdfmetrics.registerFont(TTFont(fontname,'{directory that you put the font}/ipag.ttf'))
p = canvas.Canvas(response,pagesize=A4)
p.setFont(fonatname,13)
p.drawString(100,100,u'日本語,中国語,韓国語')
p.showPage()
p.save()