Dompdf not supporting chinese languages

1.6k views Asked by At

Chinese characters work fine in the HTML page, but when i try to covert HTML to PDF with below code, all Chinese characters got converted to question marks.

I tried to use all types of chinese font libraries but still no success. Please help me fix it.

  $html = '<!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <meta http-equiv="Content-Type: application/pdf; charset=utf-8"/>

    <link rel="stylesheet" href="style.css">
    <div style="width:800px; height:970px; padding:20px;  border: 10px      solid #787878">
    <style>
body {
   body {font-family: "simsun"}
}
 </style>
 <div style="width:750px; height:915px; padding:20px;  border: 5px solid  #787878">
  </br>

    <div><img class="imgA1"  src="logo.png" ></div>
    <!--<img class="imgB1" src="logo.png">-->
    </br></br></br></br>
    <h6 style="font-size:16px !important; text-align:center;"> <b>'.$goal.'</b></h6><br/><br/>
    <b>立約人</b></br></br>
    甲方 : <span style="font-size:18px;"><b>'.$user[0]['user_name'].'<b>               </span>
   <br><br>
   乙方 : <span style="font-size:18px;"><b>'.$judge_name.'</b></span><br/><br/>
    <b>四. 本合約壹式貳份,雙方各執壹份為憑。</b><br/><br/>
    裁判簽名___________________<br/><br/>s中華民國 月   日
</div>
</div></html>'; 

$dompdf->loadHtml($html);


$dompdf->setPaper('A4', 'landscape');

/* Render the HTML as PDF */
$dompdf->render();

header('Content-Type: application/pdf; charset=utf-8');
header('Content-disposition: inline; filename="' .  $no . '.pdf"', true);
/* Output the generated PDF to Browser */
$dompdf->stream();
1

There are 1 answers

0
Jamiul Alam On
 @font-face {
        font-family: 'Firefly Sung';
        font-style: normal;
        font-weight: 500;
        src: url(http://eclecticgeek.com/dompdf/fonts/cjk/fireflysung.ttf) 
                 format('truetype');
    }

    * {
        font-family: Firefly Sung, DejaVu Sans, Verdana, Arial, sans-serif;
    }