PHP 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 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); 

enter image description here

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

其他信息

我使用的字体是 Tajawal,它是一种阿拉伯语谷歌字体:https://fonts.google.com/specimen/Tajawal?subset=arabic

我已将这些添加到我的 html 文档中:

ini_set('default_charset','UTF-8');
<html dir="rtl" lang="ar">
<Meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

我还尝试在数据库中插入相同的阿拉伯语字段,它们运行良好。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)