如何解决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);
如图所示(生成的 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 举报,一经查实,本站将立刻删除。