mpdf不支持中文字体

时间:2018-04-23 07:42:27

标签: javascript php jquery mpdf

我正在使用mpdf。当我尝试将中文单词写入WriteHtml()时,生成的pdf包含方框而不是那些字体。

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);

我尝试了mpdf 6.0及以上版本,但结果仍然相同

请咨询

谢谢。

3 个答案:

答案 0 :(得分:0)

尝试:

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in='UTF-8';

答案 1 :(得分:0)

我修好了,请检查一下,如果你有同样的错误

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);

答案 2 :(得分:0)

在对象创建过程中使用模式

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

并在其中写入您的utf-8内容