mpdf not supporting arabic and chinese fonts

2020-02-28 06:26发布

I am using mpdf. When I supplied the arabic and chinese words to the WriteHtml(), the resulting pdf containing square boxes instead of those fonts.

Please suggest!

Sample fonts:

I am testing أنا العالم 我的世界

标签: php mpdf
5条回答
一纸荒年 Trace。
2楼-- · 2020-02-28 06:40

You need to enable the support of PDF Asian font like this:

$pdf = $this->pdf->load();
$pdf->useAdobeCJK = true;
$pdf->SetAutoFont(AUTOFONT_ALL);
查看更多
趁早两清
3楼-- · 2020-02-28 06:42

Add this to your php code:

$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

in css file make sure that you have:

font-family: dejavusanscondensed;
direction: rtl;

and finly make sure that all DejaVuSans*.ttf files are in ttfonts folder

查看更多
太酷不给撩
4楼-- · 2020-02-28 06:43

I guess this is pretty late but I've tried this for Arabic language using version 8.x and it worked for me.

$mpdf = new Mpdf();
$mpdf->autoLangToFont = true;
$mpdf->WriteHTML($html);

I needed to add $mpdf->autoLangToFont = true; because some fonts don't render arabic and that's where it gets messy with squares, etc.

for more information here

查看更多
祖国的老花朵
5楼-- · 2020-02-28 06:54

On mPDF 6.0, we found this made Cantonese work for us:

$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;

Seems SetAutoFont is now deprecated.

查看更多
女痞
6楼-- · 2020-02-28 06:55

Have you looked at the latest release, version 6? It contains a lot of upgrades for foreign languages.

查看更多
登录 后发表回答