如何在FPDF中处理特殊字符[英] How to handle special characters in FPDF

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

问题描述

我目前正在使用FPDF来创建PDF,但意识到FPDF类似乎无法处理特殊字符,例如Tilde的类别.我知道来自我数据库的字符串是UTF-8,但无论如何这些字符都被剥离了.我尝试更改字符集,这样:

$myString= iconv('UTF-8', 'windows-1252', $someString);

但是,仍然什么都没有.除了使用TFPDF以外,还有其他解决方案吗?我已经对原始FPDF类进行了一些实质性的更改,不想全部重做.

谢谢 杰森

编辑

当我使用FPDF并尝试打印这样的内容时:

   $this->SetFont( 'Arial', 'B', 19 );
   $this->SetLineWidth(1);
   $this->Line(10,10,290 ,10);
   $this->Cell(300,15,iconv("UTF-8", "CP1250//TRANSLIT",'Días, Miércoles, Sábado,miércoles, Año'),0,1,'C');

它打印出来:

días,miércoles,sábado,miércoles,a〜no

推荐答案

检查允许Unicode字体的FPDF/HTML2PDF的扩展名.

http://www.mpdf1.com/mpdf1.com/mpdf/index.php /p>

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

问题描述

I am currently using FPDF to create pdf's but realized that the FPDF class doesn't seem to be able to handle special characters, like tilde's for example. I know the strings coming from my database are UTF-8, but these characters get stripped out anyway. I've tried changing the character set, like this:

$myString= iconv('UTF-8', 'windows-1252', $someString);

But, still nothing. Is there any other solutions, other than using tFPDF? I've made some substantial changes to the original FPDF class and don't want to have to redo it all.

thanks jason

EDIT

When I use FPDF and try to print something like this:

   $this->SetFont( 'Arial', 'B', 19 );
   $this->SetLineWidth(1);
   $this->Line(10,10,290 ,10);
   $this->Cell(300,15,iconv("UTF-8", "CP1250//TRANSLIT",'Días, Miércoles, Sábado,miércoles, Año'),0,1,'C');

And it prints out:

Días, Miércoles, Sábado,miércoles, A~no

推荐答案

Checkout the extension of FPDF/HTML2PDF called mPDF that allows Unicode fonts.

http://www.mpdf1.com/mpdf/index.php