我遇到了同样的问题,并通过下载字体并使用以下字体声明从我的 Web 服务器中的本地文件运行它来解决它:
@font-face {
font-family: 'PT Sans';
src: url( '/public/inc/fonts/PTS55F-webfont.eot');
src: url( '/public/inc/fonts/PTS55F-webfont.eot?#iefix') format('embedded-opentype'),
url( '/public/inc/fonts/PTS55F-webfont.woff') format('woff'),
url( '/public/inc/fonts/PTS55F-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
我能够在Font Squirrel上找到这种字体,但你的里程可能会有所不同。
我认为谷歌的字体会发生什么,它试图只加载它认为这个浏览器想要的格式,这对于 WebKit 来说是 woff (我相信)。但wkhtmltopdf
无法在 PDF 中嵌入 woff 字体,因此默认为无衬线字体。通过声明所有这些,TrueType 字体被包括在内,这是 PDF 实际使用的字体。
此外,您需要在任何字体系列 CSS 定义中定义要用作第一个字体的字体,否则 wkhtmltopdf 将忽略它。