问题
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:
Download the fonts & upload them to mPDF's fonts directory
/ttfonts
Declare the font-family you need to use in
config_fonts.php
under:$this->fontdata
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');
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