如何使用mPDF生成PDF并向其中添加自定义Google字体? [英] How to generate PDF using mPDF and add custom Google font to it?
问题描述
我正在使用mPDF PHP库生成PDF.我能够使用默认字体配置成功生成它.但是,我想在PDF中呈现Google字体.我尝试使用此链接中提到的步骤,但是没有工作.下面是我使用的代码.
I am generating PDF using mPDF PHP library. I am able to successfully generate it using the default font configuration. However, I want to render a Google font in my PDF. I tried using the steps mentioned in this link, but it did not work. Below is the code I use.
$mPDFO = new mPDF('utf-8', 'A4', 0, '', 10, 10, 10, 0, 0, 0, 'L');
有人可以帮助我在mPDF中使用Google字体吗?
Can anyone help me using Google Font in mPDF ?
推荐答案
如mPDF文档中所述,无法通过在HTML中引用它们来直接使用远程字体.请按照以下步骤使用自定义字体:
As mentioned in mPDF's documentation, it's not possible to use remote fonts directly by referencing them in the HTML. Follow the below steps to use custom fonts:
-
下载字体和将它们上传到mPDF的字体目录
/ttfonts
在$this->fontdata
现在是主要部分.您需要在创建的实例中提及字体家族,以调用mPDF的对象,而这正是您想念的对象,例如:
Now comes the main part. You need to mention the font-family in the instance that you create to call mPDF's object which is what you missed, like so:
$mPDFO = new mPDF('utf-8', 'A4', 0, 'Source Sans Pro', 10, 10, 10, 0, 0, 0, 'L');
最后调用SetFont
方法,如实例下方的$mPDFO->SetFont('Source Sans Pro');
Finally call the SetFont
method like $mPDFO->SetFont('Source Sans Pro');
just below your instance
这篇关于如何使用mPDF生成PDF并向其中添加自定义Google字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!