Dompdf并设置不同的字体系列 [英] Dompdf and set different font-family
问题描述
当生成PDF时,它会完全忽略应用于CSS的font-family
属性.而不是说 Verdana ,它使用了 Times New Roman.,所以我的CSS看起来像:
When generating a PDF it totally ignores my font-family
attribute applied to my CSS. Instead of say Verdana, it uses Times New Roman. So my CSS look like:
.sub-header {
font-size: 1.4rem;
text-transform: uppercase;
font-family: NeutraText-Book !important;
padding-bottom: 1.5rem;
}
PDF的生成方式如下:
The PDF is generated like this:
$pdf = PDF::loadHTML($view);
return $pdf->stream();
如何设置想要的字体?
推荐答案
PDF文档内部支持以下字体:Helvetica,Times-Roman,Courier,Zapf-Dingbats和&符号(均使用Windows ANSI编码). dompdf将在PDF中嵌入任何引用的字体,只要该字体已被预加载或dompdf可以访问并在CSS @font-face
规则中引用即可.为了产生用于类型设置的字体指标,必须进行加载过程.
PDF documents internally support the following fonts: Helvetica, Times-Roman, Courier, Zapf-Dingbats, & Symbol (all using Windows ANSI encoding). dompdf will embed any referenced font in the PDF so long as it has been pre-loaded or is accessible to dompdf and referenced in a CSS @font-face
rule. The loading process is necessary in order to produce the font metrics used for type setting.
dompdf支持与基础R& OS PDF类相同的字体:只要字体规格(.afm/.ufm)可用,类型1(.pfb)和TrueType(.ttf).捆绑的基于PHP的php-font-lib提供了对加载和子设置字体的支持.
dompdf supports the same fonts as the underlying R&OS PDF class: Type 1 (.pfb) and TrueType (.ttf) so long as the font metrics (.afm/.ufm) are available. The bundled, PHP-based php-font-lib provides support for loading and sub-setting fonts.
加载字体的过程取决于您的需求和服务器访问权限.可以通过三种方式加载字体:
The process for loading a font varies depending on your needs and server access. There are three ways you can load a font:
- 使用CSS @ font-face规则在运行时加载字体.
- 从命令行使用dompdf/load_font.php.
- 在随附的管理网站中浏览dompdf/www/fonts.php.
使用CSS @ font-face规则在运行时加载字体
不需要命令行访问.只要您要加载的字体在线可用,您就可以通过CSS轻松加载它.
No command line access required. So long as the font you want to load is available online you can load it easily via CSS.
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: normal;
src: url(http://themes.googleusercontent.com/static/fonts/opensans/v8/cJZKeOuBrn4kERxqtaUH3aCWcynf_cDxXwCLxiixG1c.ttf) format('truetype');
}
从命令行使用dompdf/load_font.php
如果您可以访问命令行,则加载字体非常简单:
If you have access to the command line then loading a font is as simple as:
[php] load_font.php "NeutraText-Book" /path/to/neutratext.ttf
运行不带任何参数的命令以查看帮助文本.不过很快,这些参数是:字体名称,普通字体文件,粗体字体文件,斜体字体文件,粗体斜体字体文件
Run the command without any parameters to see help text. Quickly, though, the parameters are: name of the font, normal font file, bold font file, italic font file, bold-italic font file
在随附的管理网站中浏览dompdf/www/fonts.php
不言自明(示例).您唯一需要做的就是确保您已经修改了管理员用户名/密码组合
Self-explanatory (sample). The only thing you need to do is make sure you've modified the admin username/password combo
注意:从dompdf 0.7.0开始,默认情况下将不包括load_font.php和管理站点
改编自dompdf Wiki( Unicode操作方法,
Adapted from the dompdf wiki (Unicode How-To, About Fonts and Character Encoding) and other sources.
这篇关于Dompdf并设置不同的字体系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!