PHP encoding problem, PDF file character error

Asked

Viewed 1,046 times

2

Well I’m with a problem that apparently is not very unusual, I’ve seen some similar questions and none of the answers helped me.

I have a form HTML where the information entered in it is being captured via POST for PHP, so far so good. To save this data as PDF I’m using the library mPDF 6.0. Basically I’m using a page HTML as a pro model PDF and the information collected by PHP shall be replaced by the.

The error is that the data that was taken by PHP cannot have accents or "ç" since they appear in a strange way, but this does not happen with the HTML, soon I have a part of the PDF with correct accent that the template page on HTML and what comes from PHP does not accept accentuation.

Example of what happens:

Nome do PDF caso tenha acento

inserir a descrição da imagem aqui
Note that you have accent in HTML without problems and in the PHP part the error happens.

Some things I’ve tried:

Place Header in PHP: header('Content-Type: text/html; charset=utf-8')

In HTML files the utf8 meta: meta charset="utf-8"

Save files to UTF-8, everyone is already like this.

And finally I tried this conversion that doesn’t make much sense but it was a suggestion I saw in some answers: $pdf = mb_convert_encoding($pdf, 'UTF-8', 'UTF-8');

Without success the problem remains even being all in UTF-8.

Codes:

Phomularius

<body>
    <form method="POST" action="pdf/index.php" enctype="multipart/form-data" onsubmit="return checkFile();">

        Número de Protocolo:<input type="text" name="f_protocolo" id="protocol"> Marca para Registro:<input type="text" name="f_registro">

    </form>
</body>

Model:

    <div>

        <p>Número de protocolo: #f_protocolo</p>


        <p>Marca para registro: #f_registro</p>

    </div>
</fieldset>

PHP:

inserir a descrição da imagem aqui

If anyone has any idea what might be going on, I accept suggestions.

Thank you in advance.

  • 1

    Try to use $mpdf->WriteHTML(utf8_decode($pdf)); and remove mb_convert_enconding.

  • I tried to use and now when I try to send the form appears "HTML contains invalid UTF-8 Character(s)" I managed to fix this with another line of code but the accent error still persists, but it was worth the try.

  • 1

    In your Voce template set the charset in the header? If not, try doing so.

  • The model I put "<meta charset="UTF-8">" since it is HTML.

  • 1

    Then try to remove the header('Content-Type: text/html; charset=utf-8') . It can happen to duplicate the charset and get all weird anyway. mPDF is a boring library to stir hehehe. Or try to make $mpdf->Writehtml(utf8_encode($pdf));

  • I’m starting to find it really boring, the problem continues, if I can’t soon I’ll look for another method to generate PDF maybe it’s the library.

  • 1

    If it’s all UTF-8 tries to remove the conversions utf8_encode.

  • Nothing yet, I think the problem is not in PHP, maybe it is the same mPDF. Anyway I appreciate the help.

  • Please do not use images of your code in the question, so it makes it very difficult for the people who want to help you, copy and paste the code, if you do not know how to find it, let someone else die for you ...

  • I appreciate the warning, but now I know that, that was one of the first questions I asked here in the O.R., I don’t make that mistake anymore. =/

Show 5 more comments
No answers

Browser other questions tagged

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