Agent Skills
› DuskBotAI/duskbot
› pdf-files
pdf-files
GitHub解决reportlab生成PDF时特殊符号(如货币符号)乱码问题,指导注册支持Unicode的TTF字体并验证渲染效果。
触发场景
使用reportlab生成PDF
PDF中特殊字符显示为方块
需要自定义PDF字体
安装
npx skills add DuskBotAI/duskbot --skill pdf-files -g -y
SKILL.md
Frontmatter
{
"name": "pdf-files",
"description": "Making a PDF with reportlab: register a TTF font first so symbols such as ₹, € and curly quotes render."
}
PDF files
reportlab's built-in fonts (Helvetica, Times) have no ₹ and draw it as a black box. Before drawing text, register a TTF font that has it and use it everywhere:
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
import glob
path = next(iter(glob.glob("/usr/share/fonts/**/DejaVuSans.ttf", recursive=True) + glob.glob("/usr/share/fonts/**/FreeSans.ttf", recursive=True)), None)
if path:
pdfmetrics.registerFont(TTFont("Body", path))
Then use "Body" as the font name (and in paragraph styles). Open the finished PDF's text (pdftotext) once to check the
symbols came through before you attach it.
版本历史
- 18df35a 当前 2026-11-22 04:40


