mpdf not supporting chinese fonts

2019-09-02 08:38发布

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

require 'mpdf/mpdf.php';
$mpdf->allow_charset_conversion = false;
$pdf = $this->pdf->load();
$pdf->useAdobeCJK = true;
$pdf->SetAutoFont(AUTOFONT_ALL);
$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8']); 
$mpdf->SetHeader('|<h2>Booking Invoice</h2>|');
$mpdf->setFooter('{PAGENO}'); 
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;    
$mpdf->SetDisplayMode('fullpage');
 ob_start();

 include "test.php";
$html = ob_get_contents();
ob_end_clean();

$mpdf->WriteHTML($html);

i tried mpdf 6.0 and above version, but still same result

Please advice

Thank you.

3条回答
女痞
2楼-- · 2019-09-02 09:10

Try to:

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in='UTF-8';
查看更多
▲ chillily
3楼-- · 2019-09-02 09:16

I fix it, please check this if u have same error

header('Content-Type: text/html; charset=UTF-8');
    include("mpdf/mpdf.php");

            $mpdf=new \mPDF('+aCJK','A4','','',15,10,16,10,10,10);
            $mpdf->SetHeader('|Booking Invoice|');
    $mpdf->setFooter('{PAGENO}'); 
            ob_start();
            include('cis.php');

          $html = ob_get_contents();
            ?>


            <?php
            $html = ob_get_clean();


            $html = iconv('UTF-8', 'UTF-8//IGNORE', $html);
            $html = iconv('UTF-8', 'UTF-8//TRANSLIT', $html);



            $mpdf->SetAutoFont();
            $mpdf->autoScriptToLang = true;
            $mpdf->autoLangToFont   = true;



            $mpdf->WriteHTML($html);
查看更多
该账号已被封号
4楼-- · 2019-09-02 09:18

Use mode on object creation

$mpdf = new Mpdf(['mode' => 'UTF-8']);

and write your utf-8 content to it

查看更多
登录 后发表回答