【发布时间】:2015-09-06 08:28:05
【问题描述】:
我在使用 TCPDF 库在 php 中生成 pdf 时遇到问题。我需要正确显示孟加拉字体。我尝试添加一些孟加拉字体(即 SolaimanLipi.ttf、SutonnyOMJ.ttf、Siyamrupali.ttf、Nikosh.ttf 等)。我可以在 pdf 上看到孟加拉字体,但字体显示不正确。这个词放错地方了。
通过添加此字体,我看到 /fonts/ 目录中成功创建了 3 个文件“solaimanlipi.ctg.z”、“solaimanlipi.php”和“solaimanlipi.z”。以及我可以在 pdf 上看到孟加拉字体,但这种字体错位/分散。我附上一张我实际看到的图片。
这是显示上述结果的代码:
<?php
$strData = file_get_contents('./data3.txt');
?>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<style>
@font-face
{
font-family: myUniFont;
src: url(./SolaimanLipi_22-02-2012.ttf);
}
</style>
</head>
<body>
<span style="font-family: myUniFont;"><?php echo $strData; ?></span>
</body>
</html>
我使用下面的代码在我的 pdf 中使用相同的字体:
$strBNFont = TCPDF_FONTS::addTTFfont('./SolaimanLipi_22-02-2012.ttf', 'TrueTypeUnicode', '', 32);
$pdf->SetFont($strBNFont, '', 8, '', 'false');
这就是它在 PDF 中的样子::(
编辑#1
哇! ;(天哪!
亲爱的先生,问题不在于 pdf/tcPDF 库,也不在于它本身的字体文件。
请检查以下 php 代码:
<?php
header('Content-type: image/png');
$text = 'তোমাদের জন্য মুক্তিযুদ্ধের গল্প';
$font = './Fonts/SolaimanLipi_22-02-2012.ttf';
$im = imagecreatetruecolor(600, 300);
$bg_color = imagecolorallocate($im, 255, 255, 255);
$font_color = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 599, 299, $bg_color);
imagettftext($im, 20, 0, 10, 50, $font_color, $font, $font);
imagettftext($im, 20, 0, 10, 120, $font_color, $font, $text);
imagepng($im);
imagedestroy($im);
?>
这是它在浏览器上导出/渲染 png 图像的方式:
当我尝试使用 imagettftext 函数在图像文件上打印文本时,它也破坏了字符:(
因为我确定这不是字体问题,因为我刚刚测试了 60 多种字体并且都坏了.. 而浏览器(html 代码)非常正确地显示它们。
所以,我觉得这比我的大脑可以容纳/处理的要大得多;(
所以,像你这样的专家可能只有出路:)
再次感谢您的光临
【问题讨论】:
-
没有人熟悉 tcPDF unicode 问题?
-
我被困得很厉害,在这里真的需要一些帮助......
-
这不是 Unicode 的问题,而是 TCPDF 无法处理 Brahmic 脚本的呈现。如果你真的打算使用 TCPDF……你有安装了支持 Pango 的 ImageMagick 吗?
标签: php pdf unicode fonts tcpdf