Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP FPDF阿拉伯语文本隔离_Php_Pdf Generation_Fpdf - Fatal编程技术网

PHP FPDF阿拉伯语文本隔离

PHP FPDF阿拉伯语文本隔离,php,pdf-generation,fpdf,Php,Pdf Generation,Fpdf,我正在尝试生成一个阿拉伯语的pdf文档,我有相同的英文格式使用fpdf。在做了一些研究之后,我最终用tfpdf和tcpdf替换了fpdf。后来,我的pdf格式被弄乱了,无法100%使用阿拉伯语。所以我选择了tfpdf 在对tfpdf进行更多研究后,我最终得到了以下代码: //to add custom font from unicode folder $pdf->AddFont('Tajawal', '', 'Tajawal-Medium.ttf', true); //to set th

我正在尝试生成一个阿拉伯语的pdf文档,我有相同的英文格式使用fpdf。在做了一些研究之后,我最终用tfpdf和tcpdf替换了fpdf。后来,我的pdf格式被弄乱了,无法100%使用阿拉伯语。所以我选择了tfpdf

在对tfpdf进行更多研究后,我最终得到了以下代码:

//to add custom font from unicode folder
$pdf->AddFont('Tajawal', '', 'Tajawal-Medium.ttf', true); 
//to set the custom font 
$pdf->SetFont('Tajawal','',18,true);
    
//helper function to rever the arabic string since I get the output reversed in the pdf
function utf8_strrev($str){
    preg_match_all('/./us', $str, $ar);
    return implode(array_reverse($ar[0]));
}
//$answer comes from a php and is an arabic string        
$pdf->MultiCell(0 , 7, utf8_strrev($answer),1); 

如图所示(生成的pdf截图),阿拉伯字母是分开/不相交的,但由于反向辅助功能,顺序正确。我们如何在tfpdf中解决此问题

其他信息

我使用的字体是Tajawal,它是一种阿拉伯语谷歌字体:

我已将以下内容添加到我的html文档中:

ini_set('default_charset', 'UTF-8');
<html dir="rtl" lang="ar">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
ini\u集(“默认字符集”、“UTF-8”);

我还尝试在数据库中插入相同的阿拉伯语字段,但效果非常好。

fFPDF不支持阿拉伯语。