在 wkhtmltopdf 中使用自定义字体 [英] use custom fonts with wkhtmltopdf
问题描述
我正在尝试在使用 wkhtmltopdf 生成的 PDF 中使用自定义字体.我读到你不能使用 google webfonts 并且 wkhtmltopdf 使用 truetype .ttf 文件.任何人都可以确认吗?所以我从google webfont下载了一个.ttf文件并放在我的服务器上,然后使用了字体:
I am trying to use custom fonts in my PDF generated with wkhtmltopdf. I read that you can't use google webfonts and that wkhtmltopdf uses truetype .ttf file. Can anyone confirm that? So I downloaded a .ttf file from google webfont and put in on my server, then used the font face:
@font-face {
font-family: Jolly;
src: url('../fonts/JollyLodger-Regular.ttf') format('truetype');
}
和字体系列:
<style type = "text/css">
p { font-family: 'Jolly', cursive; }
</style>
现在应该用 Jolly Lodger 字体呈现的文本根本没有出现,页面是空白的.
And now the text that is supposed to render with Jolly Lodger font doesn't appear at all, page is blank.
我做错了什么?
PS:我尝试使用不同的 .ttf 文件.
PS: I tried with different .ttf files.
推荐答案
由于它是 Google Web 字体,因此您无需在样式表中编写 @font-face
只需使用以下链接标签即可您的源代码:
Since it is a Google Web font you need not to write @font-face
in you style sheet just use following link tag in your source code:
<link href='http://fonts.googleapis.com/css?family=Jolly+Lodger' rel='stylesheet' type='text/css'>
和
<style type = "text/css">
p { font-family: 'Jolly Lodger', cursive; }
</style>
会起作用.
顺便说一下,在您的代码中,您将 @font-face
系列定义为 font-family: Jolly;
并将其用作 p { font-家庭:'Jolly Lodger',草书;}
那是错误的,因为它与字体系列名称不匹配.
By the way, in your code you are defining @font-face
family as font-family: Jolly;
and using it as p { font-family: 'Jolly Lodger', cursive; }
that is wrong, because it's mismatching font-family name.
这篇关于在 wkhtmltopdf 中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!