Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a Japanese string inside HTML?

I am creating a PDF using DOMPDF. The pdf contains some images and strings. I am printing this values as php variables inside my HTML Layout and then converting HTML to PDF. Some of my strings are in Japanese. But it rendering in PDF as ????.

I used <meta http-equiv="Content-Type" content="text/html; charset=utf-8">. But nothing happends..

My code used is..

 $bio_tbl = '<html style="margin:20px 20px 0px; padding:0;">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
 <body style="margin:0; padding:0;">
  <table style="vertical-align: top;">
  <tr>
   <td style="vertical-align: top;padding-top:4px;">'.$model_first_img.'</td>
   <td style="vertical-align:top;">
   <table style="margin:0px 0px 5px 3px;">
    <tr>
      <td style="width:220px;vertical-align:top;">'.$model_second_img.'</td>
      <td style="width:220px;vertical-align:top;">'.$model_third_img.'</td>
    </tr>
    </table>
    <table style="margin:0px 0px 5px 3px;">
    <tr>
      <td style="width:220px;vertical-align:top;">'.$model_forth_img.'</td>
      <td style="width:220px;vertical-align:top;">'.$model_fifth_img.'</td>
    </tr>
    </table>
    <table style="margin:0px 0px 0px 3px;">
    <tr>
      <td style="width:220px;vertical-align:top;">'.$text.'</td>
      <td style="width:220px;vertical-align:top;"><img style="width:210px;height:210px;" src="'.$black_image_path.'"></td>
    </tr>
  </table>
  </td>
   <td>
<img src="'.$copy_img.'">
</td>
</tr>
<tr>
  <td style="vertical-align:top;text-align:center;font-size:20px;margin-top:5px"><b><u>BIO</u></b></td>
</tr>
<tr>
      <td style="vertical-align:top;">
      <div style="text-align:left;font-size:14px; margin-bottom:10px; margin-top:10px;">'.$bio_text.'</div>
      </td>
    </tr>
   </table>
 </body>
</html>';  

Converting to PDF using following code..

 $dompdf = new DOMPDF();
$dompdf->set_base_path($path);
$dompdf->load_html($bio_tbl);
$dompdf->set_paper("a3", "portrait");
$dompdf->render();
$pdf = $dompdf->output();
$filename = $pdfname;
$dir = DRUPAL_ROOT .'/sites/default/files/temp_pdf/bio_'.$filename;
file_put_contents($dir,$pdf); 

All helps appreciated..

like image 467
Abin Avatar asked Jan 20 '26 02:01

Abin


1 Answers

Try to use :

$dompdf->load_html($content, 'UTF-8');
like image 93
AnkiiG Avatar answered Jan 21 '26 16:01

AnkiiG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!