FPDF中的塞尔维亚语字符[英] Serbian characters in FPDF

本文是小编为大家收集整理的关于FPDF中的塞尔维亚语字符的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在fpdf http://www.fpdf.org/ p>

$ myString ="запослени都

我使用了$ pdf->写入和多电器...所有结果都是相同的.

utf8_decode($mystring) -> ????????? ? ?????????????/??????? ?????? ?????

iconv('UTF-8', 'utf-8//TRANSLIT', $mystring) -> ЗапÐ3⁄4ѕлÐμÐ1⁄2Ð ̧ у рачуÐ1⁄2Ð3⁄4Ð2Ð3⁄4Ð ́Ñ•Ñ‚Ð2у/Ñ•Ñ€Ð3⁄4Ð ́Ð1⁄2Ð3⁄4Ð1⁄4 раР́Ð1⁄2Ð3⁄4Ð1⁄4Ð1⁄4Ðμѕту

非常感谢

推荐答案

我个人不会在PDF中使用UTF-8,因为文件大小对我来说很大.在这种情况下,我使用字体嵌入以避免大文件大小.

FPDF类可以用西欧语言以外的许多语言生产文档:中欧,西里尔,希腊语,波罗的海和泰语,前提是您拥有带有所需角色集的truetype或type1字体.也可以使用UTF-8支持.

对于UTF-8支持,您必须使用 tfpdf 基于FPDF. TFPDF接受UTF-8编码文本.请 在该网站的底部.

转换为UTF-8:

如果您使用上面的说明(从链接)并从文件中加载UTF-8字符串,则不需要转换为UTF-8.

// this file file must be saved in UTF-8 before:
$str = file_get_contents('Text-saved-in-UTF-8.txt');

在其他情况下:

您必须使用 mb_convert_encoding 和不iconv./p>

对于塞尔维亚(拉丁),这是'iso-8859-2'或'windows-1250'.对于塞尔维亚(西里尔),这是'iso-8859-5'或'windows-1251'.这些编码将提供正确显示的变性拉丁字符,例如žćđš.

在您的情况下:

$mystring = "Запослени у рачуноводству/сродном радном месту";

您必须写:

$str = mb_convert_encoding($mystring, 'UTF-8', 'iso-8859-5');

$str = mb_convert_encoding($mystring, 'UTF-8', 'windows-1251');

您的php文件必须保存在iso-8859-5或windows-1251之前(但是 not 在UTF-8中).

然后您在tfpdf中使用它.

本文地址:https://www.itbaoku.cn/post/2090932.html

问题描述

I have problem with Serbian language in FPDF http://www.fpdf.org/

$mystring = "Запослени у рачуноводству/сродном радном месту";

I used $pdf->Write and MultiCell... all are same result.

utf8_decode($mystring) -> ????????? ? ?????????????/??????? ?????? ?????

iconv('UTF-8', 'utf-8//TRANSLIT', $mystring) -> ЗапÐ3⁄4ѕлÐμÐ1⁄2Ð ̧ у рачуÐ1⁄2Ð3⁄4Ð2Ð3⁄4Ð ́Ñ•Ñ‚Ð2у/Ñ•Ñ€Ð3⁄4Ð ́Ð1⁄2Ð3⁄4Ð1⁄4 раР́Ð1⁄2Ð3⁄4Ð1⁄4Ð1⁄4Ðμѕту

thank so much

推荐答案

Personally I would not use UTF-8 in my PDFs because the file size will big for me. I use font embedding in this case to avoid big file size.

The FPDF class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. UTF-8 support is also available.

For the UTF-8 support you have to use tFPDF which is based on FPDF. tFPDF accepts UTF-8 encoded text. Please read all this instructions and then download the ZIP file on the bottom from this site.

Convertation to UTF-8:

You do not need a convertation to UTF-8 if you use instructions above (from link) and load a UTF-8 string from a file like follows:

// this file file must be saved in UTF-8 before:
$str = file_get_contents('Text-saved-in-UTF-8.txt');

In other case:

You have to use mb_convert_encoding and not iconv.

For Serbian (Latin) this is either 'iso-8859-2' or 'windows-1250'. For Serbian (Cyrillic) this is 'iso-8859-5' or 'windows-1251'. These encodings will provide correct display of diacritic Latin characters such as žćđš.

In yor case for:

$mystring = "Запослени у рачуноводству/сродном радном месту";

You have to write:

$str = mb_convert_encoding($mystring, 'UTF-8', 'iso-8859-5');

or

$str = mb_convert_encoding($mystring, 'UTF-8', 'windows-1251');

Your PHP file must be saved in iso-8859-5 or in windows-1251 before (but not in UTF-8).

And then you use this in tFPDF.