0

I am making a system that automatically generates a contract, the problem is that I am unable to print some of the characters in PDF.

Sérgio Avilla (My name, for example, goes like this) -> It should come out like this: Sérgio Avilla.

Below is the simplified application code.

<?php
require_once __DIR__ . '/vendor/autoload.php';
include 'config.php';
header("Content-type: text/html; charset=utf-8");

function file_get_contents_utf8($fn) {
    $content = file_get_contents($fn);
    return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}

$html = file_get_contents_utf8("contratos/".$contrato);

$mpdf = new \Mpdf\Mpdf();

$mpdf->WriteHTML($html);

$mpdf->Output();

?>

I would be grateful if anyone could help me. I've already tested, $ html, if printed directly on the screen gives no problems, all the right characters, the problem is mpdf down.

  • This is the English version of SO. All questions/answers/comments need to be in English. – M. Eriksson Jan 11 '20 at 10:36
  • Have a look at this question: [UTF-8 all the way through](https://stackoverflow.com/questions/279170/utf-8-all-the-way-through). It might shed some light over the issue. – M. Eriksson Jan 11 '20 at 10:47

1 Answers1

0

On the contract html file there was a charset =... , meta tag, I just changed it to charset = utf-8 and it worked.

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

Before: <meta http-equiv=Content-Type content="text/html; charset=windows-1252">