使用FPDF显示波兰字符的问题?

时间:2012-05-24 15:23:10

标签: php utf-8 fpdf polish iso-8859-2

我们在尝试使用FPDF生成的发票上正确显示波兰字符时遇到问题。我不确定是否是FPDF或我们正在使用的字体正在创建问题。两者都在服务器上正确设置了UTF-8 PHP配置和MySQL配置。所有波兰语字符都在网站上正确显示来自代码和来自数据库的文本
在FPDF中:
  - 原文:
Zażółćgęśląjaźń:

  - //没有额外的工作显示为
结果:ZażóÅ,ćgÄ™>lÄ...jaźœ:

  - //应用以下更改后

    html_entity_decode(utf8_decode($string),ENT_QUOTES)

结果: Za?ó??克; 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źń:正确显示,则只有在发票本身中才会显示正确的字符。

3 个答案:

答案 0 :(得分:2)

您还可以使用TFPDF,它是FPDF项目的一个分支,它通过使用PHP多字节函数支持Unicode。

http://fpdf.org/en/script/script92.php

答案 1 :(得分:1)

尝试使用Dejavu字体。我用过这个捷克字符和UTF-8,效果很好。 用法:

$pdf->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
$pdf->SetFont('DejaVu','',14);
//the rest

答案 2 :(得分:0)

我基于arial使用arialpl和arialbpl(粗体)。我的文件与您的符号编号分配不同。

Arialpl.php:

<?php
$type='Type1';
$name='ArialMT';
$desc=array('Ascent'=>905,'Descent'=>-212,'CapHeight'=>716,'Flags'=>32,'FontBBox'=>'[-46 -283 979 896]','ItalicAngle'=>0,'StemV'=>70,'MissingWidth'=>750);
$up=-106;
$ut=73;
$cw=array(
    chr(0)=>750,chr(1)=>750,chr(2)=>750,chr(3)=>750,chr(4)=>750,chr(5)=>750,chr(6)=>750,chr(7)=>750,chr(8)=>750,chr(9)=>750,chr(10)=>750,chr(11)=>750,chr(12)=>750,chr(13)=>750,chr(14)=>750,chr(15)=>750,chr(16)=>750,chr(17)=>750,chr(18)=>750,chr(19)=>750,chr(20)=>750,chr(21)=>750,
    chr(22)=>750,chr(23)=>750,chr(24)=>750,chr(25)=>750,chr(26)=>750,chr(27)=>750,chr(28)=>750,chr(29)=>750,chr(30)=>750,chr(31)=>750,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
    ','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
    'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944,
    'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833,
    'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>750,chr(128)=>750,chr(129)=>750,chr(130)=>750,chr(131)=>750,
    chr(132)=>750,chr(133)=>750,chr(134)=>750,chr(135)=>750,chr(136)=>750,chr(137)=>750,chr(138)=>750,chr(139)=>750,chr(140)=>750,chr(141)=>750,chr(142)=>750,chr(143)=>750,chr(144)=>750,chr(145)=>750,chr(146)=>750,chr(147)=>750,chr(148)=>750,chr(149)=>750,chr(150)=>750,chr(151)=>750,chr(152)=>750,chr(153)=>750,
    chr(154)=>750,chr(155)=>750,chr(156)=>750,chr(157)=>750,chr(158)=>750,chr(159)=>750,chr(160)=>278,chr(161)=>667,chr(162)=>333,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>667,chr(167)=>556,chr(168)=>333,chr(169)=>667,chr(170)=>667,chr(171)=>611,chr(172)=>611,chr(173)=>333,chr(174)=>611,chr(175)=>611,
    chr(176)=>400,chr(177)=>556,chr(178)=>333,chr(179)=>222,chr(180)=>333,chr(181)=>292,chr(182)=>500,chr(183)=>333,chr(184)=>333,chr(185)=>500,chr(186)=>500,chr(187)=>375,chr(188)=>500,chr(189)=>333,chr(190)=>500,chr(191)=>500,chr(192)=>722,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>556,
    chr(198)=>722,chr(199)=>722,chr(200)=>722,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>667,chr(205)=>278,chr(206)=>278,chr(207)=>722,chr(208)=>722,chr(209)=>722,chr(210)=>722,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>722,chr(217)=>722,chr(218)=>722,chr(219)=>722,
    chr(220)=>722,chr(221)=>667,chr(222)=>611,chr(223)=>611,chr(224)=>333,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>222,chr(230)=>500,chr(231)=>500,chr(232)=>500,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>556,chr(237)=>278,chr(238)=>278,chr(239)=>615,chr(240)=>556,chr(241)=>556,
    chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>549,chr(248)=>333,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>278,chr(255)=>333);
$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 /dcroat /nacute /ncaron 245 /ohungarumlaut 248 /rcaron /uring 251 /uhungarumlaut 254 /tcommaaccent /dotaccent';
$file='arialpl.z';
$size1=5911;
$size2=25241;
?>

导入后:

{
        $this->AddFont('arialpl', '', 'arialpl.php');
        $this->AddFont('arialbpl', '', 'arialbpl.php');
}

并设置字体:

{
         $this->SetFont('arialpl', '', 12);
}

我还必须使用文本转换:

{
$text = iconv('UTF-8', 'iso-8859-2//TRANSLIT//IGNORE', $text);
}