如何在HTML中显示日语字符串?

时间:2015-08-17 08:54:50

标签: php html character-encoding

我正在使用 DOMPDF 创建PDF。 pdf包含一些图像和字符串。我在 HTML布局中将此值打印为 php变量,然后将 HTML转换为PDF 。我的一些字符串是日语。但它将 PDF 呈现为 ????

我使用了<meta http-equiv="Content-Type" content="text/html; charset=utf-8">。但没有任何事情发生..

我使用的代码是..

 $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>';  

使用以下代码转换为PDF ..

 $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); 

所有人都很感激..

1 个答案:

答案 0 :(得分:1)

尝试使用:

$dompdf->load_html($content, 'UTF-8');