TCPDF UTF-8. Lithuanian symbols not showing up

前端 未结 15 670
-上瘾入骨i
-上瘾入骨i 2020-12-01 06:47

Im using latest TCPDF version(5.9). But have some strange problems with encoding. I need Lithuanian language symbols like: ąčęėįšųūž. But get only few of it. Other remain li

15条回答
  •  一整个雨季
    2020-12-01 06:52

    Just discovered this same situation when trying to render Romanian text using the default Helvetica font. In doing some investigation I found that the tcpdf library treats it's default fonts (referred to as "core" fonts) as Latin1 characters so even if you tell it to use UTF-8 encoding and set the unicode flag, it will literally translate your text to Latin1 equivalents prior to rendering. The default behavior of the library is, if it finds a Latin1 equivalent, to translate each character that it can find an equivalent for otherwise it translates the character as '?'.

    This can be found inside the TCPDF class in the following method chain: Write() -> Cell() -> getCellCode() -> _escapetext().

    Inside of _escapetext() you can see it is checking for $this->isunicode then checking the selected font to see if it's type is core|TrueType|Type1. If it is, it will take the string an "latinize" it for you by way of the UTF8ToLatin1() method. This is where the '?' translations are taking place.

    My recommendation would be to use a custom unicode font (like Deja Vu Sans) that is similar to the default font you are after. That worked for me in my current situation.

提交回复
热议问题