html contains invalid utf-8 character (s) MPDF 6.0

1

I have blob text in the database with the accent and such ..

When I pass it by SE is not put utf-8_encode in the read variable returns this error.

I asked the question because I already tested the other answers in the stack and did not solve ...

Here is the code with the last solution attempt

$mpdf = new mPDF();
$mpdf->mirrorMargins = true;
$mpdf->SetDisplayMode('fullpage','two');
$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'UTF-8');
$mpdf->WriteHTML($PDFContent);
ob_clean();
$mpdf->Output("./pdf_contratos/".$nome_c_pdf.".pdf");
    
asked by anonymous 21.02.2017 / 17:56

1 answer

1

The content of your PDF is in an incorrect character encoding. The utf8_encode function converts your charset from your php to UTF-8 . Obviously this will break from server to server, because the configuration will be different.

The correct one in your case is to use the mb_convert_encoding function. Your only problem is that you are requesting a conversion from UTF-8 to UTF-8 .

Change the following line:

$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'UTF-8');

To:

$PDFContent = mb_convert_encoding($PDFContent, 'UTF-8', 'ISO-8859-1');

Comment : I'm considering that the text is encoded in ISO-8858-1 , if this is not your case, change accordingly.

    
21.02.2017 / 18:10