如何在 MPDF 中使用 Font Awesome? [英] How to use Font Awesome with MPDF?
问题描述
我正在使用 Zend Framework 并使用 mpdf 创建 PDF.
我正在尝试使用 fontawesome 来表示一些文章,但是 fontawesome 的字体没有正确呈现下面是代码.
$stylesheet = file_get_contents("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");$stylesheet .= file_get_contents("https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css");$this->mpdf->WriteHTML($stylesheet,1);$this->mpdf->WriteHTML($html,2);$this->mpdf->allow_charset_conversion = true;$this->mpdf->charset_in = 'windows-1252';$this->mpdf->Output();
我在 html 中使用的代码
公司名称</span>
提前致谢.
如今,这是一种过时的方法,只能在遗留系统上使用.
我推荐 @Arie 的以下答案,修改最新版本的 mPDF 字体和/或由 Composer 安装,在实例化类时传递参数.
简单的方法:
复制
fontawesome-webfont.ttf
文件到/mPDF/ttfonts/
目录.编辑
/mPDF/config_fonts.php
,搜索以$this->fontdata
开头的数组并添加:
fontawesome";=>大批('R' =>fontawesome-webfont.ttf",),
- 使用新的字体系列正确更改文档 CSS.例如:
$stylesheet = '.company-name { font-family: fontawesome;}';
- 当你实例化这个类时,让第一个参数留空:
例如:
$mpdf = new mPDF();
或
$mpdf = new mPDF('', 'A4');
我使用 mPDF 6.0 进行了测试并且它有效.
此外,mPDF 手册解释了如何使用更多选项进行操作:mPDF 6.x 中的字体>
I am using Zend Framework and creating PDF with mpdf.
I am trying to use fontawesome for denoting some of the articles but the fonts of font awesome are not rendering properly
below is the code .
$stylesheet = file_get_contents("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
$stylesheet .= file_get_contents("https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css");
$this->mpdf->WriteHTML($stylesheet,1);
$this->mpdf->WriteHTML($html,2);
$this->mpdf->allow_charset_conversion = true;
$this->mpdf->charset_in = 'windows-1252';
$this->mpdf->Output();
The code I am using in the html
<span class="company-name"> name of the company</span>
Thanks in advance.
EDIT: Nowadays, this is an obsolete method, and should only be used on legacy systems.
I recommend the answer below, from @Arie, to modify the mPDF font in its recent versions and/or if it was installed by Composer, passing the parameters when instantiating the class.
The easy way:
Copy
fontawesome-webfont.ttf
file into/mPDF/ttfonts/
directory.Edit
/mPDF/config_fonts.php
, search the array started by$this->fontdata
and add to it:
"fontawesome" => array(
'R' => "fontawesome-webfont.ttf",
),
- Change your document CSS properly, with your new font family. Eg.:
$stylesheet = '.company-name { font-family: fontawesome; }';
- When you instantiate the class, let the first parameter in blank:
Eg.:
$mpdf = new mPDF();
or
$mpdf = new mPDF('', 'A4');
I am tested with mPDF 6.0 and it worked.
Also, the mPDF manual explain how to do it with more options: Fonts in mPDF 6.x
这篇关于如何在 MPDF 中使用 Font Awesome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!