mPDF不转换字符'&并且使得以下所有内容都无法翻译。生成pdf但是字符'&amp ;;之后的所有代码'没有打印。这是我的代码:
<table>
<tr>
<p>test example & test example</p>
</tr>
</table>
我使用这个PHP代码来创建pdf输出:
<?php
$divcontent = $_POST['divcontent'];
$html='<html><head></head><body style="background-color:#FFFFFF;height:100%; width:100%;">';
$html.= $divcontent;
$html.='</body></html>';
//==============================================================
include(dirname(__FILE__)."/../../libs/MPDF57/mpdf.php");
@$mpdf=new mPDF('c');
@$mpdf->SetDisplayMode('fullpage');
@$stylesheet = file_get_contents(realpath(dirname(__FILE__)."/../..")."/css/style.css");
$mpdf->setFooter('{PAGENO}');
@$mpdf->WriteHTML($stylesheet,1);
@$mpdf->WriteHTML($html);
$rand = rand();
@$mpdf->Output(realpath(dirname(__FILE__)."/../..")."/file.pdf",'F');
?>
答案 0 :(得分:0)
<table>
<tr>
<p>test example <?php echo htmlspecialchars('&') ?> test example</p>
</tr>
</table>
答案 1 :(得分:0)
试试这个:
$mpdf->charset_in='utf-8';
您应该将其添加到HTML的主题部分:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
确保您的服务器Apache或Nginx也使用utf-8作为默认字符集。
答案 2 :(得分:0)
After days I found the problem. The ajax call not coded character and now adding "encodeURIComponent (divcontent)" and passing the result to the php function, should not use "html_entity_decode", mPDF print special characters such as "&".