Search code examples
phppdf-generationfpdf

FPDF Character encoding


I've seen many question on SO about generating PDFs in PHP with help of FPDF and also many problems with encoding. My native language is Slovak, so far I found out that I should be using ISO-8859-2 encoding. I tried converting UTF-8 to ISO-8859-2 through

iconv('utf-8', 'ISO-8859-2', $text)

but fpdf throws error that it can't recognize some characters.

I am trying to generate some text like this

$pdf->Cell(0, 0, self::text('ZÁKAZNÍK'), '', '', 'L');


    function text($text)
    {
//        return $text;
//        return mb_convert_encoding($text, 'ISO-8859-1', 'UTF-8');
        return iconv('utf-8', 'cp1252', html_entity_decode($text));
    }

Any idea? It should work for characters like (ľščťžýáíéôúä)


Solution

  • Use this instead:

    iconv('UTF-8','iso-8859-2//TRANSLIT//IGNORE',$text);

    That should work.