html - php mPDF, impossible to set font-family and font-size
Get the solution ↓↓↓Solution:
There are two ways with which u can add your font to generated pdf:
1. Setting font to mpdf
Keep your fonts in ttfonts folder in mpdf lib. Then, in config_fonts.php file add your font in array :
$this->fontdata = array( "YourNewFont" => array( 'R' => "YourNewFont.ttf"));
Then set font to the mpdf object using :
$mpdf->SetFont('YourNewFont');
Now, your fornt is set. Using $mpdf->WriteText('My Text'); will add text to pdf with the set font.
2. Use font in Html
Add your font family in a css file using @font-face {}
Then, import that css file like below:
$stylesheet = file_get_contents('MyStyleWithFont.css');
$mpdf->WriteHTML($stylesheet,1);
Now, you can use your font with html. Define font-family for the text in either css file or inline with html. Use $mpdf->WriteHTML(My Text); to print html.
Answer
Solution:
I know i'm late, hope it would be helpful for someone in future. While creating mPDF object set the mod parameter as 'UTF-8' or ' ' instead of 'c'. 'c' will force system to use core fonts only and thus neglect the custom font.
$mpdf = new mPDF('UTF-8','A4')
Note: this is applicable for mPDF v6 and below
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: string literal contains an unescaped line break
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.