I am using a Grails rendering plugin to generate PDF.
我正在使用Grails渲染插件来生成PDF。
I want to include CSS with my PDF to render it nicely. I found an example on the rendering plugin website
我想用我的PDF包含CSS来很好地渲染它。我在渲染插件网站上找到了一个例子
I put the CSS below in print media so that it works for PDF, but this does not work for me. I also do not know how to change the font from Arial to another font. Can someone explain this to me?
我将CSS放在打印介质中,以便它适用于PDF,但这对我不起作用。我也不知道如何将字体从Arial更改为另一种字体。谁可以给我解释一下这个?
The plugin uses Arial font with this CSS:
该插件使用Arial字体与此CSS:
@font-face {
src: url(path/to/arial.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
body {
font-family: "Arial Unicode MS", Arial, sans-serif;
}
3 个解决方案
#1
2
You need arialuni.ttf not just arial.ttf download it here: http://www.findthatfonts.com/search-2683324-hTTF/fonts-download-search-engine-ARIALUNI.ttf.htm
你需要arialuni.ttf而不仅仅是arial.ttf在这里下载:http://www.findthatfonts.com/search-2683324-hTTF/fonts-download-search-engine-ARIALUNI.ttf.htm
Then
You have to give your @font-face a font-family name like this:
你必须给@ font-face一个这样的字体系列名称:
@font-face {
font-family: "Font-Name";
src: url(path/to/font.ttf); // you have to add your font.ttf file to the server in a folder like assets/css/fonts or something.
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
body {
font-family: "Font-Name", Arial, sans-serif; // you called your font Font-Name in the @font-face so now you can use it as Font-Name everywhere else in you css.
}
Otherwise your arialuni.ttf has no name so you can't use it in other divs in your css.
否则你的arialuni.ttf没有名字,所以你不能在你的CSS中的其他div中使用它。
#2
1
The next is working for me good:
接下来对我有好处:
@font-face {
font-family: 'Calibri';
src: url(${grailsApplication.config.grails.serverURL}/fonts/calibri.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
The -fs-pdf-font-encoding
should be set in Identity-H
. And after it you can add something like
应在Identity-H中设置-fs-pdf-font-encoding。在它之后你可以添加类似的东西
body {
font-family: 'Calibri';
}
#3
0
It doesn't really matter what name you give the font, as long as you choose a name for the src you provide between te @font-face brackets, like font-family: "SomeName";
. Now, you can use the font everywhere using font-family: "SomeName"
.
只要您为te @ font-face括号之间提供的src选择一个名称,就像font-family:“SomeName”;那么,给字体命名的名称并不重要。现在,您可以使用font-family:“SomeName”在任何地方使用该字体。
#1
2
You need arialuni.ttf not just arial.ttf download it here: http://www.findthatfonts.com/search-2683324-hTTF/fonts-download-search-engine-ARIALUNI.ttf.htm
你需要arialuni.ttf而不仅仅是arial.ttf在这里下载:http://www.findthatfonts.com/search-2683324-hTTF/fonts-download-search-engine-ARIALUNI.ttf.htm
Then
You have to give your @font-face a font-family name like this:
你必须给@ font-face一个这样的字体系列名称:
@font-face {
font-family: "Font-Name";
src: url(path/to/font.ttf); // you have to add your font.ttf file to the server in a folder like assets/css/fonts or something.
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
body {
font-family: "Font-Name", Arial, sans-serif; // you called your font Font-Name in the @font-face so now you can use it as Font-Name everywhere else in you css.
}
Otherwise your arialuni.ttf has no name so you can't use it in other divs in your css.
否则你的arialuni.ttf没有名字,所以你不能在你的CSS中的其他div中使用它。
#2
1
The next is working for me good:
接下来对我有好处:
@font-face {
font-family: 'Calibri';
src: url(${grailsApplication.config.grails.serverURL}/fonts/calibri.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: Identity-H;
}
The -fs-pdf-font-encoding
should be set in Identity-H
. And after it you can add something like
应在Identity-H中设置-fs-pdf-font-encoding。在它之后你可以添加类似的东西
body {
font-family: 'Calibri';
}
#3
0
It doesn't really matter what name you give the font, as long as you choose a name for the src you provide between te @font-face brackets, like font-family: "SomeName";
. Now, you can use the font everywhere using font-family: "SomeName"
.
只要您为te @ font-face括号之间提供的src选择一个名称,就像font-family:“SomeName”;那么,给字体命名的名称并不重要。现在,您可以使用font-family:“SomeName”在任何地方使用该字体。