1

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.

kul amin
  • 49
  • 1
  • 1
  • 7
  • Is that works for You? Why are You doing `$mpdf->allow_charset_conversion = false;` before instantiate the `$mpdf` object? – bigwolk Apr 23 '18 at 07:53
  • Possible duplicate of [How to use mPDF for Chinese Language](https://stackoverflow.com/questions/47036954/how-to-use-mpdf-for-chinese-language) – bigwolk Apr 23 '18 at 09:29
  • https://stackoverflow.com/questions/47036954/how-to-use-mpdf-for-chinese-language also got error – kul amin Apr 26 '18 at 09:51

3 Answers3

1

Try to:

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in='UTF-8';
bigwolk
  • 418
  • 4
  • 17
  • Also can't, same square boxes only appear , please help me for this – kul amin Apr 23 '18 at 09:10
  • Have You tried different conversion format? Docs says about 10 different formats for chinese: `EUC-CN, HZ, GBK, GB18030, EUC-TW, BIG5, CP950, BIG5-HKSCS, ISO-2022-CN, ISO-2022-CN-EXT` – bigwolk Apr 23 '18 at 09:13
  • i don't know how, please let me know how to do that – kul amin Apr 23 '18 at 09:14
  • Try this as I pasted You in the answer, but with one of these formats. And paste it after `$mpdf = new \Mpdf\Mpdf(); `. – bigwolk Apr 23 '18 at 09:16
  • include("mpdf/mpdf.php"); $mpdf = new \Mpdf\Mpdf(); $mpdf->allow_charset_conversion = true; $mpdf->charset_in='UTF-8'; $mpdf->SetHeader('|

    Booking Invoice

    |'); $mpdf->setFooter('{PAGENO}');// Giving page number to your footer. $mpdf->SetDisplayMode('fullpage'); // Buffer the following html with PHP so we can store it to a variable later ob_start(); ?> WriteHTML($html);
    – kul amin Apr 26 '18 at 07:53
  • I attached code above but still same square boxes only appear, i am using MPDF 6.0 Please help me for this – kul amin Apr 26 '18 at 07:54
  • on what kind of system did you VIEW your pdf file? Was it Adobe's reader, or another program? Did you also try to experiment with the option to subset Chinese fonts when saving the pdf? Furthermore, is the output of your included `cis.php` or `test.php` well formatted and in the same encoding (utf-8)? – mxl Feb 07 '19 at 19:16
0

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);
kul amin
  • 49
  • 1
  • 1
  • 7
0

Use mode on object creation

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

and write your utf-8 content to it