How to generate PDF using mPDF and add custom Google font to it?

六眼飞鱼酱① 提交于 2019-12-13 16:14:47

问题


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');

Can anyone help me using Google Font in mPDF ?


回答1:


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:

  1. Download the fonts & upload them to mPDF's fonts directory /ttfonts

  2. Declare the font-family you need to use in config_fonts.php under: $this->fontdata

  3. 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');

  4. Finally call the SetFont method like $mPDFO->SetFont('Source Sans Pro'); just below your instance



来源:https://stackoverflow.com/questions/47287750/how-to-generate-pdf-using-mpdf-and-add-custom-google-font-to-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!