首页 > 解决方案 > 无法使 ReportLab 正确打印 unicode 字体

问题描述

我正在尝试使用 hygothic-medium 字体打印韩文字符。我在 site-packages\reportlab\fonts 文件夹下的字体为 'korean.h2gtrm.ttf' 文件。我做了以下事情: -

 pdfmetrics.registerFont(UnicodeCIDFont(TTFont('HYGothic- 
 Medium','korean.h2gtrm.ttf')))
 pdfmetrics.registerFontFamily('HYGothic-Medium',normal='HYGothic- 
 Medium',bold='HYGothic-Medium',italic='HYGothic- 
 Medium',boldItalic='HYGothic- 
 Medium')
 addMapping('HYGothic-Medium',0, 0, 'korean.h2gtrm') #normal
 addMapping('HYGothic-Medium', 0, 1, 'korean.h2gtrm')
 addMapping('HYGothic-Medium',1, 0, 'korean.h2gtrm')
 addMapping('HYGothic-Medium',1, 1, 'korean.h2gtrm')
 pstyle= ParagraphStyle(name='KOR', fontName = 'HYGothic-Medium', 
  fontSize = 10 ))
  p=Paragraph(text,pstyle)) # where text is my Korean characters
  story.append(p) # error !!

我收到以下错误:-

   Can't map determine family/bold/italic for hygothic-medium
   paragraph text '<para>\uc724\uadfc Machine</para>' caused exception

有什么建议么 ?。

标签: python-3.xreportlabunicode-string

解决方案


推荐阅读