Reportlab:启用加密的亚洲字体不起作用

发布于 2024-10-26 03:18:39 字数 763 浏览 5 评论 0原文

我在我的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 reader 无法读取 pdf。例如,对于简体中文,我们会从 Adob​​e Reader 中收到“无法找到字体“STSong-Light”的错误。

任何人都知道什么加密被破坏而无法正常工作吗?

I have been using Asian fonts (Chinese simplified/tradional, Japanese, and Korean) in my reportlab generated pdfs without issuse for a while now. However recently we have decided to enable the encryption options like this:

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 
) 

For non Asian languages the encryption works as expected. When we use Asian fonts with encryption the pdf cannot be read by adobe reader. For example with simplified Chinese we get a "Cannot find the font "STSong-Light" error from Adobe Reader.

Anyone have any ideas on what encryption is breaking to not make this work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吖咩 2024-11-02 03:18:39

我也有同样的问题。这可能无法解决您的问题。
但是,如果我将其指定为日语,
你可以通过安装TTFont来解决这个问题(在这个例子中它是IPA gothic),
并设置字体。

所以,通过安装其他语言的字体,你可以解决这个问题
这不酷。

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() 

I had the same problem. This might not solve your problem.
But, If I specify it into Japanese,
you can solve it by installing TTFont(in this example it is IPA gothic),
and set the font.

So, by installing another languages fonts, you can solve the problem though
this is not cool.

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() 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文