如何在MPDF中使用Font Awesome? [英] How to use Font Awesome with MPDF?

查看:51
本文介绍了如何在MPDF中使用Font Awesome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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">&#xf21b; 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆