Export diacritics in pdf using php and dompdf

2019-07-12 20:27发布

I have a problem with exporting accented characters such as "şăţî" in PDF documents. These characters are stored normally in a database but when I tried to export to PDF the character ş is transformed to %C5%9F and so on. I think the problem is from dompdf library. Now I do preg_replace but is not a good solution. Someone was met with such problem?

My code:

   public function generateTitlePage($company, $number_cadastral='', $adresa_beneficiar='', $administrator='',                                      $verificator='', $number_certificate='', $executor='', $date='')
{
    $this->load->library('dompdf_gen');
    $dompdf = new DOMPDF();
    $company = preg_replace('/%C3%A2/','â',$company);
    $company = preg_replace('/%C3%AE/','î',$company);
    $company = preg_replace('/%C5%9F/','ş',$company);
    $company = preg_replace('/%C5%A3/','ţ',$company);



    $html = <<<HTML
        <html>
        <head>
            <meta charset="UTF-8">
        </head>
        <body>
            <div style="margin-top:20px;text-align: center;font-weight: bold">SOCIETATE CU RASPUNDERE LIMITATA&nbsp;$company</div>
            <div style="margin-top: 100px; text-align: right; padding-right:130px;">
                <span style="padding-right: 10px">Nr.Cadastral:</span>$company
                <div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
            </div>
 </body>
        </html>
 HTML;

    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("welcome.pdf");
}

With blank spaces I have the same problem; blank space is transformed into .%27 and 27%.

0条回答
登录 后发表回答