html - php mPDF, impossible to set font-family and font-size ← (PHP, CSS, HTML)
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
Source
See also:
About the technologies asked in this question PHP PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.https://www.php.net/
CSS CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.https://www.w3.org/TR/CSS/#css
HTML HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.https://www.w3.org/html/
Welcome to programmierfrage.com
programmierfrage.com is a question and answer site for professional web developers, programming enthusiasts and website builders. Site created and operated by the community. Together with you, we create a free library of detailed answers to any question on programming, web development, website creation and website administration.
Get answers to specific questions
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Help Others Solve Their Issues
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.