Problem with accent when generating PDF with dompdf

3

I am generating a PDF report using the dompdf API, and words that contain accent are not being displayed correctly.

I put the charset = 'utf-8' tag inside the head, but it does not solve the problem

<meta charset='utf-8'/>

In php elements if I do:

<?php echo utf8_decode($variavel); ?>

Content is displayed correctly with accentuation ...

* But HTML elements continue with accent problem ...

  

Example

Code

<?php
ob_start('geraPDF'); 
?>

<html>
    <head>
        <meta charset='utf-8'>

    <style>
        p{
            border:1px solid black;
            box-shadow:5px 5px 5px #ccc;
            width:90%;
            padding:5px;
        }
    </style>

     </head>

    <body>

        <b>Empresa: </b><?php echo utf8_decode($empresas); ?><br>

        <b>Data: </b><?php echo date('d/m/Y',strtotime($dt)); ?><br>

        <b>Nº da OS: </b><?php echo $os; ?><br>

        <b>Nº Orçamento: </b><?php $norcamento; ?><br><br>

    </body>
</html>

<?php
// Importa arquivo de config da classe DOMPDF
require_once 'dompdf/dompdf_config.inc.php';

/**
 *  Função ob_get_clean obtém conteúdo que está no buffer
 *  e exclui o buffer de saída atual.
 *  http://br1.php.net/manual/pt_BR/function.ob-get-clean.php 
 */
$html = ob_get_clean(); 
$pdf = new DOMPDF();
$pdf->load_html($html);
$pdf->render();
$pdf->stream(date('d/m/Y').'_orcamento.pdf', array('Attachment'=>0));
?>

The result does not come out as expected in the pdf ... what could be happening?

    
asked by anonymous 11.09.2015 / 01:06

1 answer

2

First try adding the PHP header:

header('Content-type: text/html; charset=UTF-8')

If this solution does not work, edit the dompdf_config.inc.php file:

mb_internal_encoding('UTF-8');
def("DOMPDF_UNICODE_ENABLED", true);

The above answer is based on a response on stackoverflow internationally.

    
15.09.2015 / 02:48