首页 > 解决方案 > python FPDF如何加粗内联文本

问题描述

如何在写入文档时将内联字符串加粗。

我尝试了特殊字符\033,但它们似乎只适用于控制台打印而不是pdf输出,因为它们在pdf中显式打印为\033......还有其他方法可以将字符串格式化为粗体吗?

编辑:

我的意思是,我需要将非 ASCII 字符打印到文件中,我该如何完成它

标签: pythonpyfpdf

解决方案


使用的字体必须包含加粗样式

请参阅鼓舞 Arial 和 Times 的示例,网址为

https://pyfpdf.readthedocs.io/en/latest/reference/set_font/index.html#example

# Times regular 12
pdf.set_font('Times')
# Arial bold 14
pdf.set_font('Arial', 'B', 14)
# Removes bold
pdf.set_font('')
# Times bold, italic and underlined 14
pdf.set_font('Times', 'BIU')

另请参阅https://pyfpdf.readthedocs.io/en/latest/reference/add_font/index.htmlhttps://pyfpdf.readthedocs.io/en/latest/reference/set_font/index.html


推荐阅读