Fpdf和特殊字符 [英] Fpdf and special characters

查看:132
本文介绍了Fpdf和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试用内置字体写出一些特殊字符,有什么办法吗?

I am trying to write out some special characters with built in fonts, is there any way to do this?

$ str =‘ščťžýáíéäúň§ôúűűáéóüöűú’;
$ str = iconv('UTF-8','windows-1252',$ str);

$str = 'ščťžýáíéäúň§ôúőűáéóüöűú'; $str = iconv('UTF-8', 'windows-1252', $str);

结果是一个字母Š,不太好。 :)

the result is one letter Š, not too good. :)

推荐答案

我知道这是一个老话题,但是我这个周末遇到了这个问题,花了很长时间在Google上搜索和玩,所以这里节省了时间。
http://fpdf.org/en/script/script92.php是使用变音符号(带重音符号)的方法。但是您需要向其中添加一些代码...
将其插入第617行

I know it's an old thread, but I've faced the issue this weekend and spent a longtime Googling and playing, so here's a time saver. http://fpdf.org/en/script/script92.php is the way to go to use diacritics (accented characters). But you need to add some code to it... Slot this in at line 617

 /* Modified by Vinod Patidar due to font key does not match in dejavu bold.*/
    if ( $family == 'dejavu' && !empty($style) && ($style == 'B' || $style == 'b') ) {
        $fontkey = $family.' '.strtolower($style);
    } else {
        $fontkey = $family.$style;  
    }
    /* Modified end here*/

然后更改

if($family=='arial')
        $family = 'helvetica';

 if($family=='arial'||$family='dejavu')
        $family = 'helvetica';

然后不要在示例 DejaVu Sans Condensed中使用该字体,因为 Condensed似乎意味着粗体版本不包含所有字符

Then don't use the font in the example "DejaVu Sans Condensed" because Condensed seems to mean the Bold version doesn't contain all the characters

您可能还需要从常规fpdf.php脚本中添加getPageWidth和getPageHeight方法,因为它比tfpdf.php更新!

You may also need to add the getPageWidth and getPageHeight methods from the normal fpdf.php script as it is newer than tfpdf.php!

具有上述更改

$pdflabel->AddFont('DejaVu','','DejaVuSans.ttf',true);  
$pdf->AddFont('DejaVu','B','DejaVuSans-Bold.ttf',true);

用欧洲语言造好人

这篇关于Fpdf和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆