如何在名为FPDI的php库中设置UTF-8编码? 这里的图书馆:https://www.setasign.com/products/fpdi/manual/
代码:
$pdf = new Fpdi();
$pdf->AddPage();
$pdf->setSourceFile('PdfDocument.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 10, 10, 100);
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'Zażółcić gęślą jaźń');
$pdf->Output();
[溶液]
第一:我必须添加带有正确字母的新字体
$pdf->AddFont('DejaVu','','DejaVuSansCondensed.php');
$pdf->SetFont('DejaVu', '', 10, '', false);
SECOND:关于FPDI用户的FPDF库: 有可能的编码:
cp1250 (Central Europe)
cp1251 (Cyrillic)
cp1252 (Western Europe)
cp1253 (Greek)
cp1254 (Turkish)
cp1255 (Hebrew)
cp1257 (Baltic)
cp1258 (Vietnamese)
cp874 (Thai)
ISO-8859-1 (Western Europe)
ISO-8859-2 (Central Europe)
ISO-8859-4 (Baltic)
ISO-8859-5 (Cyrillic)
ISO-8859-7 (Greek)
ISO-8859-9 (Turkish)
ISO-8859-11 (Thai)
ISO-8859-15 (Western Europe)
ISO-8859-16 (Central Europe)
KOI8-R (Russian)
KOI8-U (Ukrainian)
我发送给pdf的字符串是UTF-8(我通过mb_detect_encoding
函数检查过),需要在cp1250上进行转换。
$str = iconv('UTF-8', 'cp1250', 'zazółcić gęślą jaźń');
另一个解决方案 尝试使用:
$pdf->SetFont('freeserif', '', 14, '', true);