我正在尝试创建包含正确字符的 PDF 文件,但是出现了“?”字符。 我创建了一个测试 PHP 文件,在其中尝试找到最佳解决方案。如果在浏览器中打开 HTML 文件,则看起来没问题。
UTF-8 --> UTF-8 : X Ponuka číslo € černý Češký
但是当我查看这个PDF时,我看到了这个。
UTF-8 --> UTF-8 : X Ponuka ?íslo € ?erný ?ešký
这是我的全部代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>č s š Š</title>
</head>
<body>
<?php
require_once("dompdf/dompdf_config.inc.php");
$tab = array("UTF-8", "ASCII", "Windows-1250", "ISO-8859-2", "ISO-8859-1", "ISO-8859-6", "CP1256");
$chain = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <style></style><title>č s š Š</title></head><body>';
foreach ($tab as $i)
{
foreach ($tab as $j)
{
$chain .= "<br> $i --> $j : ".iconv($i, $j, 'X Ponuka číslo € černý Češký <br>');
}
}
$chain .= '<p style="font-family: firefly, verdana, sans-serif;">??????X Ponuka číslo € černý Češký <br></p></body></html>';
echo $chain;
echo 'X Ponuka číslo € černý Češký <br>';
$filename = 'pdf/_1.pdf';
$dompdf = new DOMPDF();
$dompdf->load_html($chain, 'UTF-8');
$dompdf->set_paper('a4', 'portrait'); // change these if you need to
$dompdf->render();
file_put_contents($filename, $dompdf->output());
?>
</body>
</html>
我做错了什么?我尝试了很多我找到的选项 :( 有任何想法吗?