FPDF with iconv from utf8mb4

2.9k views Asked by At

I have a string coming from MySql DB, encoded in utf8mb4. I am rendering a pdf with FPDF for PHP, and I tried to convert it with iconv:

iconv('utf8mb4', 'cp1252',$myString);

This fails telling me "Notice: iconv(): Wrong charset, conversion from utf8mb4' tocp1252' is not allowed". If I try with

iconv('utf-8', 'cp1252',$myString);

I get "Notice: iconv(): Detected an illegal character in input string".

Without iconv I get multiple ascii chars in place of special chars, and it is not fine.

Is there any way to output this value correctly?

2

There are 2 answers

1
Hilarius L. Doren On

try this one to IGNORE character which is not allowed in the charset

iconv('utf-8', 'cp1252//IGNORE',$myString);
0
Nillus On

I tried, it did't work. I solved this by using a version of FPDF that allows utf8: TFPDF. It is fully retrocompatible, provided that you add its new font (ttf).