如何在ReportLab Python中设置字体kerning?

发布于 2025-01-26 08:28:35 字数 811 浏览 3 评论 0原文

我将字体添加到ReportLab,然后生成PDF,但文本已关闭Kerning。例如,在HTML中它可以按预期工作。如何在ReportLab中启用字体kerning?我尝试在段落方向上更改设置textobject.setcharspace,但没有任何理想的效果。以下是我的示例代码和预期结果。还可以在我的github上提供示例: https://github.com/czubikik.888805/reportlabkerning

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas


pdfmetrics.registerFont(
    TTFont(
        'arial',
        'arial.ttf')
)

c = canvas.Canvas("hello.pdf")
c.setFont('arial', 32)
c.drawString(10, 450, "Toned Avenue")
c.showPage()
c.save()

=“ https://i.sstatic.net/w2eax.png” rel =“ nofollow noreferrer”> reportlab(无kerning)的

文本。

I add font to reportlab, then it generates pdf, but text has kerning turned off. For example in html it works as expected. How to enable font kerning in reportlab ? I have tried changing settings in ParagraphStyle and textObject.setCharSpace but nothing has the desired effect. Below is my sample code and the expected results. Example is available also on my github: https://github.com/czubik8805/ReportLabKerning

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen import canvas


pdfmetrics.registerFont(
    TTFont(
        'arial',
        'arial.ttf')
)

c = canvas.Canvas("hello.pdf")
c.setFont('arial', 32)
c.drawString(10, 450, "Toned Avenue")
c.showPage()
c.save()

Text from reportlab (without kerning)

Text from HTML with (kerning)

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

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

发布评论

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