我必须使用reportlab.pdfbase.pdfmetrics 中的registerFontFamily 方法。我尝试向系列中添加两种字体,但无法将粗体字体与“< b>sometext </b>”一起使用。我的报告需要此功能。我只能用普通的,不知道为什么。
这是代码。
registerFont(TTFont('Own_Font', os.path.dirname(os.path.abspath(__file__)) + '\\OwnSans-Regular.ttf'))
registerFont(TTFont('OwnBold_Font', os.path.dirname(os.path.abspath(__file__)) + '\\OwnSans-Bold.ttf'))
registerFontFamily('Own_Font',normal='Own_Font',bold='OwnBold_Font')
# define parameter for the page and paragraph font
PAGE_WIDTH, PAGE_HEIGHT = landscape(A4)
STYLES = getSampleStyleSheet()
STYLES.add( ParagraphStyle(name='Text', fontName = 'Own_Font', fontSize = 10 ))
STYLES.add( ParagraphStyle(name='Centered', fontName = 'Own_Font', fontSize = 10, alignment=TA_CENTER ))
STYLES.add( ParagraphStyle(name='CenteredBig', parent=STYLES['Centered'], fontSize=18, spaceAfter=10) )
STYLES.add( ParagraphStyle(name='CenteredMedium', parent=STYLES['Centered'], fontSize=15, spaceAfter=10) )
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paragraph.py", line 916, in __init__
self._setup(text, style, bulletText or getattr(style,'bulletText',None), frags, cleanBlockQuotedText)
File "X:\tools\Python2\lib\site-packages\reportlab-2.7-py2.7-win32.egg\reportlab\platypus\paragraph.py", line 938, …Run Code Online (Sandbox Code Playgroud)