Unfortunately, there is no reply from the user, so I do not know whether installing the additional font files solved the problem. Maybe you could try downloading and installing a suitable font.
Check the list of fonts distributed or compatible with mPDF here and download mPDF fonts from here.
Can you check the pdf file properties (e.g. in Acrobat Reader, File -> Properties -> Fonts tab) and confirm whether the Sun fonts are included in the pdf file?
In the meanwhile I will investigate how mPDF handles fonts when converting from html to pdf.
I have managed to include arabic and cjk characters thanks to the answers here. Briefly, to solve the problem:
Download the Sun-ExtA and Sun-ExtB fonts from mPDF site and copy them to ‘vendor/mpdf/mpdf/ttfonts/’.
Edit the file ‘vendor/mpdf/mpdf/scr/Config/ConfigVariables.php’ and in the “AUTOMATIC FONT SELECTION” section, set to true the variables ‘autoScriptToLang’ and ‘autoLangToFont’ as in,
// AUTOMATIC FONT SELECTION
// Based on script and/or language
// mPDF 6.0 (similar to previously using function SetAutoFont() )
// 'autoScriptToLang' => false,
'autoScriptToLang' => true,
'baseScript' => Ucdn::SCRIPT_LATIN,
'autoVietnamese' => true,
'autoArabic' => true,
// mPDF 6.0 (similar to old useLang)
// 'autoLangToFont' => false,
'autoLangToFont' => true,
Beware that (as of now) the Sun-Ext fonts are not embedded in the resulting pdf file, and that displaying the japanese characters requires having a proper local font file available to substitute Sun-Ext fonts.
Do you mean that the PDF displays Japanese letters as long as my customer has any Japanese font installed on his/her computer?
That’s right, and this is the (recommended?) solution according to the mPDF manual. The font files are at the end of the Adobe’s page, look for the table under “Add ons”.
Is there any way to embed Japanese fonts?
I am investigating this possibility. As of now, the proposed changes to the configuration file cause the XB Riyaz fonts to be embedded in the pdf file, while the Sun-Ext* fonts are not. Thus, there must be another configuration option involved that I haven’t found yet (it is a quite long list).
For what it’s worth (for instance for similar future questions),
the fonts used (aka required) for each language are set in the file ‘vendor/mpdf/mpdf/scr/Language/LanguageToFont.php’, and
the correspondence between the value of the ‘$unifont’ variable and the actual font files can be found in the file ‘vendor/mpdf/mpdf/src/Config/FontVariables.php’
No matter what options I have tried, I haven’t managed to make mPDF to embed the Sun-Ext* fonts or a subset of it in the pdf file. I only managed to get the font embedded by adding the ‘sun-extb’ value to the ‘font-family’ property in the ‘template.css’ file, but then only the Japanese characters were displayed and all other text was lost, and I presume that’s not what you wanted.
A solution that may work, but I haven’t tested, would be: to create a custom field for the text in Japanese, and then modify a copy of the pdf template to display the custom field using the Japanese font as explained here. The
Another alternative is to process the pdf with a software that embeds the fonts. For instance, you could use the ‘pdftocairo’ tool of the Poppler library (Windows version here) as in,
I have tested the tool on GNU/Linux and all fonts where embedded in the new pdf file, which surprisingly was smaller (22K) than the original file (49K) in spite of containing all used fonts,