问题
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.
回答1:
Try to:
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in='UTF-8';
回答2:
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);
回答3:
Use mode on object creation
$mpdf = new Mpdf(['mode' => 'UTF-8']);
and write your utf-8 content to it
来源:https://stackoverflow.com/questions/49975788/mpdf-not-supporting-chinese-fonts