如何在MPDF中使用Font Awesome? [英] How to use Font Awesome with MPDF?
问题描述
我正在使用Zend Framework并使用mpdf创建PDF.
我正在尝试使用fontawesome来表示某些文章,但font awesome的字体无法正确呈现
下面是代码.
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();
我在html中使用的代码
The code I am using in the html
<span class="company-name"> name of the company</span>
谢谢.
推荐答案
简单方法:
1)将fontawesome-webfont.ttf
文件复制到/mPDF/ttfonts/
目录中.
1) Copy fontawesome-webfont.ttf
file into /mPDF/ttfonts/
directory.
2)编辑/mPDF/config_fonts.php
,搜索以$this->fontdata
开头的阵列并将其添加到其中:
2) Edit /mPDF/config_fonts.php
, search the array started by $this->fontdata
and add to it:
"fontawesome" => array(
'R' => "fontawesome-webfont.ttf",
),
3)使用新的字体系列正确更改文档CSS.例如:
3) Change your document CSS properly, with your new font family. Eg.:
$stylesheet = '.company-name { font-family: fontawesome; }';
4)实例化类时,将第一个参数留空:
4) When you instantiate the class, let the first parameter in blank:
例如:
$mpdf = new mPDF();
或
$mpdf = new mPDF('', 'A4');
我已经通过mPDF 6.0进行了测试,并且可以正常工作.
I am tested with mPDF 6.0 and it worked.
此外,mPDF手册还介绍了如何使用更多选项进行操作: mPDF 6.x中的字体
Also, the mPDF manual explain how to do it with more options: Fonts in mPDF 6.x
这篇关于如何在MPDF中使用Font Awesome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!