Special characters with dompdf and php

我的梦境 提交于 2019-12-10 11:47:39

问题


I have a question: I tried to export a pdf with dompdf and php but I can't do this and I dont understand where is my problem, so my code is:

public function generateTitlePage($company)
{
    $this->load->library('dompdf_gen');
    $html='
        <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        </head>
        <body>
            <div style="margin-top:20px;text-align: center;font-weight: bold">
                Company:'.$company.'
            </div>
        </body>
        <html>'; 
    $dompdf = new DOMPDF();
    $html = stripslashes($html);
    $dompdf->load_html($html, 'UTF-8');
    $dompdf->set_paper('a4', 'portrait');
    $dompdf->render();
    $dompdf->stream("welcome.pdf");
}

For example if I have ă in my pdf this symbol is converted in : %C4%83


回答1:


I tried to find similar and I found, that many other users has the same problem with UTF-8 encoding. They found solution by changing mbstring.encoding_translation to On in php.ini configuration file:

mbstring.encoding_translation = On

Or for some helped utf8_decode() function:

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


来源:https://stackoverflow.com/questions/25651096/special-characters-with-dompdf-and-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!