0

我有一些日文字符串需要使用 weasyprint 库转换为 PDF,现在日文字符显示为框,所以我想这是字体问题,我的问题是代码在我的本地操作系统上运行良好,但在 Heroku相反,它的显示框,当我无法访问系统时(在我的情况下是 Heroku),我如何才能安装和使用自定义字体 weasyprint

下面是我的代码

from weasyprint import HTML, CSS
from weasyprint.fonts import FontConfiguration

font_config = FontConfiguration()
html = HTML(string='<h1>Title here 自家製フォント工房&lt;/h1>')
css = CSS(string='''''', font_config=font_config)

html.write_pdf(
    'report.pdf', stylesheets=[css],
    font_config=font_config)
4

1 回答 1

1

通过在文件夹 .fonts中添加字体 .ttf 文件找到了解决方案,Heoku将使用该文件夹来查找字体。

然后在CSS中我会说

@font-face {
  font-family: 'Hannari-Regular';
  src: local('Hannari-Regular')
}

其中 Hannari-Regular 是字体文件的名称

于 2018-10-12T10:14:28.593 回答