0

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();
Maciej Jureczko
  • 1,560
  • 6
  • 19
  • 23
mukesh
  • 33
  • 8
  • You should run your HTML through a [validator](https://validator.w3.org). Its got some major structural and syntactical issues. Would help to see the source of your stylesheet. – BrianS Aug 28 '17 at 21:11
  • Possible duplicate of [DomPDF generation for chinese characters](https://stackoverflow.com/questions/28435198/dompdf-generation-for-chinese-characters) – BrianS Aug 28 '17 at 21:15
  • Issue solved by installation of font library. – mukesh Sep 19 '17 at 04:44

1 Answers1

0
 @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;
    }