我们在尝试让波兰语字符正确显示在使用 FPDF 生成的发票上时遇到问题。我不确定是 FPDF 还是我们使用的字体造成了问题。UTF-8 在 PHP 配置和 MySQL 配置中都在服务器上正确设置。所有波兰语字符在来自代码和来自数据库的文本都正确显示在网站上。
在 FPDF 中:
- 原始文本:
Zażółć gęślą jaźń:
- // 没有其他工作显示为
结果:ZażóÅ,ć gęślÄ... jaźń:
- // 应用以下更改后
html_entity_decode(utf8_decode($string),ENT_QUOTES)
结果:Za?ó?? g??l? ja??:
- // 应用以下更改后
iconv("UTF-8", "ISO-8859-2", $string)
结果:Za¿ó³æ gê¶l± ja¼ñ:
这发生在 Arial 和 Times 的内置字体中。我使用步骤http://www.fpdf.org/en/tutorial/tuto7.htm构建了一种名为 Tellural 的字体。但是,这似乎无法解决问题。
该字体是 Tellural.php,包含:
<?php
$type='TrueType';
$name='Tellural';
$desc=array('Ascent'=>886,'Descent'=>-216,'CapHeight'=>699,'Flags'=>32,'FontBBox'=>'[-521 -216 1213 891]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>822);
$up=-106;
$ut=73;
$fpdf_charwidths['tellural']=array(
chr(0)=>822,chr(1)=>822,chr(2)=>822,chr(3)=>822,chr(4)=>822,chr(5)=>822,chr(6)=>822,chr(7)=>822,chr(8)=>822,chr(9)=>822,chr(10)=>822,chr(11)=>822,chr(12)=>822,chr(13)=>822,chr(14)=>822,chr(15)=>822,chr(16)=>822,chr(17)=>822,chr(18)=>822,chr(19)=>822,chr(20)=>822,chr(21)=>822,
chr(22)=>822,chr(23)=>822,chr(24)=>822,chr(25)=>822,chr(26)=>822,chr(27)=>822,chr(28)=>822,chr(29)=>822,chr(30)=>822,chr(31)=>822,' '=>244,'!'=>323,'"'=>346,'#'=>539,'$'=>478,'%'=>743,'&'=>605,'\''=>185,'('=>348,')'=>348,'*'=>483,'+'=>518,
','=>289,'-'=>491,'.'=>274,'/'=>549,'0'=>518,'1'=>518,'2'=>518,'3'=>518,'4'=>518,'5'=>518,'6'=>518,'7'=>518,'8'=>518,'9'=>518,':'=>274,';'=>289,'<'=>518,'='=>518,'>'=>518,'?'=>409,'@'=>582,'A'=>602,
'B'=>606,'C'=>605,'D'=>643,'E'=>567,'F'=>553,'G'=>639,'H'=>640,'I'=>268,'J'=>268,'K'=>623,'L'=>485,'M'=>805,'N'=>666,'O'=>688,'P'=>597,'Q'=>726,'R'=>613,'S'=>486,'T'=>530,'U'=>629,'V'=>624,'W'=>914,
'X'=>571,'Y'=>532,'Z'=>562,'['=>386,'\\'=>549,']'=>386,'^'=>468,'_'=>342,'`'=>537,'a'=>586,'b'=>565,'c'=>558,'d'=>590,'e'=>558,'f'=>341,'g'=>570,'h'=>611,'i'=>275,'j'=>289,'k'=>508,'l'=>322,'m'=>873,
'n'=>586,'o'=>560,'p'=>588,'q'=>576,'r'=>371,'s'=>411,'t'=>357,'u'=>597,'v'=>569,'w'=>877,'x'=>545,'y'=>602,'z'=>483,'{'=>356,'|'=>253,'}'=>356,'~'=>537,chr(127)=>822,chr(128)=>822,chr(129)=>822,chr(130)=>822,chr(131)=>822,
chr(132)=>822,chr(133)=>822,chr(134)=>822,chr(135)=>822,chr(136)=>822,chr(137)=>822,chr(138)=>822,chr(139)=>822,chr(140)=>822,chr(141)=>822,chr(142)=>822,chr(143)=>822,chr(144)=>822,chr(145)=>822,chr(146)=>822,chr(147)=>822,chr(148)=>822,chr(149)=>822,chr(150)=>822,chr(151)=>822,chr(152)=>822,chr(153)=>822,
chr(154)=>822,chr(155)=>822,chr(156)=>822,chr(157)=>822,chr(158)=>822,chr(159)=>822,chr(160)=>244,chr(161)=>567,chr(162)=>319,chr(163)=>470,chr(164)=>591,chr(165)=>470,chr(166)=>486,chr(167)=>674,chr(168)=>304,chr(169)=>486,chr(170)=>486,chr(171)=>488,chr(172)=>562,chr(173)=>491,chr(174)=>562,chr(175)=>562,
chr(176)=>292,chr(177)=>586,chr(178)=>214,chr(179)=>293,chr(180)=>556,chr(181)=>423,chr(182)=>411,chr(183)=>376,chr(184)=>193,chr(185)=>411,chr(186)=>411,chr(187)=>459,chr(188)=>483,chr(189)=>406,chr(190)=>483,chr(191)=>483,chr(192)=>613,chr(193)=>602,chr(194)=>602,chr(195)=>602,chr(196)=>602,chr(197)=>470,
chr(198)=>605,chr(199)=>596,chr(200)=>605,chr(201)=>567,chr(202)=>528,chr(203)=>567,chr(204)=>567,chr(205)=>268,chr(206)=>268,chr(207)=>643,chr(208)=>659,chr(209)=>666,chr(210)=>666,chr(211)=>688,chr(212)=>688,chr(213)=>688,chr(214)=>688,chr(215)=>537,chr(216)=>613,chr(217)=>629,chr(218)=>629,chr(219)=>629,
chr(220)=>629,chr(221)=>532,chr(222)=>464,chr(223)=>541,chr(224)=>371,chr(225)=>586,chr(226)=>586,chr(227)=>586,chr(228)=>586,chr(229)=>341,chr(230)=>558,chr(231)=>558,chr(232)=>558,chr(233)=>558,chr(234)=>558,chr(235)=>558,chr(236)=>558,chr(237)=>224,chr(238)=>224,chr(239)=>698,chr(240)=>590,chr(241)=>586,
chr(242)=>586,chr(243)=>560,chr(244)=>560,chr(245)=>560,chr(246)=>560,chr(247)=>537,chr(248)=>371,chr(249)=>597,chr(250)=>597,chr(251)=>597,chr(252)=>597,chr(253)=>602,chr(254)=>357,chr(255)=>148);
$fpdf_charwidths['telluralB']=$fpdf_charwidths['tellural'];
$fpdf_charwidths['telluralI']=$fpdf_charwidths['tellural'];
$fpdf_charwidths['telluralBI']=$fpdf_charwidths['tellural'];
$enc='iso-8859-2';
$diff='128 /.notdef 130 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef 142 /.notdef 145 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef 158 /.notdef /.notdef 161 /Aogonek /breve /Lslash 165 /Lcaron /Sacute 169 /Scaron /Scedilla /Tcaron /Zacute 174 /Zcaron /Zdotaccent 177 /aogonek /ogonek /lslash 181 /lcaron /sacute /caron 185 /scaron /scedilla /tcaron /zacute /hungarumlaut /zcaron /zdotaccent /Racute 195 /Abreve 197 /Lacute /Cacute 200 /Ccaron 202 /Eogonek 204 /Ecaron 207 /Dcaron /Dcroat /Nacute /Ncaron 213 /Ohungarumlaut 216 /Rcaron /Uring 219 /Uhungarumlaut 222 /Tcommaaccent 224 /racute 227 /abreve 229 /lacute /cacute 232 /ccaron 234 /eogonek 236 /ecaron 239 /dcaron /dmacron /nacute /ncaron 245 /ohungarumlaut 248 /rcaron /uring 251 /uhungarumlaut 254 /tcommaaccent /dotaccent';
$file='tellural.z';
$originalsize=64356;
?>
我也使用过http://acko.net/blog/ufpdf-unicode-utf-8-extension-for-fpdf/但这似乎没有任何效果。
如果在任何函数中使用 PHP 打印,例如 Write()/ Cell() Zażółć gęślą jaźń: 正确显示,只是发票本身没有显示正确的字符。