Search code examples
encodingcharacter-encodingfpdf

Is there any 8-bit single byte character encoding, that includes russian (cyrillic) and german chars? (usage: fpdf)


I am working on a project based on fpdf and got in trouble by using special chars. I know that fpdf is not supporting any utf8 and that I have to build my own font to use special chars. This is already working for russian chars by using the iso-8859-5 encoding and also for german characters with a few other encodings.

But is it right, that there is no encoding I can use, that supports both?

In addition to that: It's a quite old and big project that is already using fpdf. I know that there are other versions like mpdf and so on, that can handle utf8, but if there is any other solution than replacing the whole system, I would really like to do that.

Thanks for your help!


Solution

  • There is no such single encoding.

    The closest I found is CP771, which supports both Lithuanian and Russian, but first: it doesn't solve your problem, second: it won't be supported by anything anyway.

    You can define separate fonts for both languages, I think that would be the easiest way.

    Following the tutorial at http://fpdf.de/tutorials/7/ I guess this would work:

    MakeFont('comic.ttf','comicDE.afm','cp1252');
    MakeFont('comic.ttf','comicRU.afm','iso-8859-5');
    

    and then:

    $pdf->AddFont('ComicDE','','comicDE.php');
    $pdf->AddFont('ComicRU','','comicRU.php');
    

    Of course this requires you to encode text and add it to the PDF in different ways depending on the language it is in, but I think that's the limitation of the library that would be hard to overcome in a different way anyway.