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

Asked

Viewed 1,004 times

1

I have a text in blob in the database with the accentuation and such..

when I run it through mpdf IF is not placed utf-8_encode in the read variable returns me this error.

I asked the question because I already tested the other answers in the stack and didn’t solve it...

here is the code with the latest 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");

1 answer

1

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

The correct in your case is to use the function mb_convert_encoding. Your only problem is that you are requesting a conversion of UTF-8 for 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');

Observing: I’m assuming the text is encoded in ISO-8858-1, if this is not your case, change accordingly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.