duanbichou4942
2015-10-26 15:20
浏览 105
已采纳

mPDF&char没有编码,我怎么办?

mPDF not convert the character ' & ' and makes all that follows is not translatable . the pdf is generated but all the code following the character ' & ' is not printed . this is my code:

<table>
    <tr>
        <p>test example & test example</p>
    </tr>
</table>

i use this php code to create the pdf output:

<?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');
?> 

图片转代码服务由CSDN问答提供 功能建议

mPDF不转换字符'&amp; 并且使得以下所有内容都无法翻译。 生成pdf但是字符'&amp ;;之后的所有代码 '没有打印。 这是我的代码:

 &lt; table&gt; 
&lt; tr&gt; 
&lt; p&gt; test example&amp; 测试示例&lt; / p&gt; 
&lt; / tr&gt; 
&lt; / table&gt; 
   
 
 

我使用此PHP代码创建pdf输出:

 &lt;?php 
 $ divcontent = $ _POST ['divcontent']; 
 $ html ='&lt; html&gt;&lt; head&gt;&lt; / head&gt;&lt; body  style =“background-color:#FFFFFF; height:100%; width:100%;”&gt;'; 
 $ html。= $ divcontent; 
 $ html。='&lt; / body&gt;&lt; / html&gt  ;'; 
 // ===========================================  =================== 
 
include(目录名(FILE __ __) “/../../库/ MPDF57 / mpdf.php”。); 
 @  $ mpdf = new mPDF('c'); 
 @ $ mpdf-&gt; SetDisplayMode('fullpage'); 
 @ $ stylesheet = file_get_contents(realpath(dirname(__ FILE __)。“/../ ..”)  。 “/ CSS / style.css文件”); 
 $的mpdf-&GT; setFooter( '{}您做生意'); 
 @ $ mpdf-&GT;的WriteHTML($样式表中,1); 
 @ $ mpdf-&GT  ; WriteHTML($ html); 
 
 $ rand = rand(); 
 @ $ mpdf-&gt;输出(realpath(dirname(__ FILE __)。“/。/ ..”)。“/ file.pdf  ”, 'F');吗?
&GT;  
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanpai6581 2015-11-11 07:49
    已采纳

    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 "&".

    点赞 打赏 评论
  • douzhuang2016 2015-10-26 15:33

    use htmlspecialchars

    <table>
        <tr>
            <p>test example <?php echo htmlspecialchars('&') ?> test example</p>
        </tr>
    </table>
    
    点赞 打赏 评论
  • douxiong2999 2015-10-26 15:46

    Try this :

    $mpdf->charset_in='utf-8';
    

    You should probably add this to the head section of the HTML :

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    

    Make sure that your server Apache or Nginx, use also utf-8 as default charset.

    点赞 打赏 评论

相关推荐 更多相似问题