dompdf\lib\fonts\dompdf_font_family_cache.php記住這個文件里面存放的是字體生成的緩存,遷移時如果覆蓋了這個文件會導致亂碼而且很難找到出錯的地方,相信我。。。。
dompdf是php把html導出pdf的工具,十分好用,除了個別css3的屬性不支持,其他都非常不錯,中文需要引用中文字體,具體辦法官方有這里簡單說下:
代碼:
$html = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
@font-face
{
font-family:ttt;
src: url(/static/font/simkai.ttf)
}
body {
font-family: ttt, sans-serif;
}</style></head>
<body >
<div style="font-family:ttt;">
測 測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試測試</div></body>
</div></body>
</html>';
//echo $html;exit;
$options = new Options();
$options->set('enable_remote', TRUE);
$dompdf = new Dompdf($options);
$dompdf->load_html( $html, 'UTF-8');;
// $dompdf->load_html( $html, ‘GBK‘);
$dompdf->render();
$dompdf->stream("sample.pdf", array("Attachment"=>0));exit;
結果:
需要說明:
10.@font-face
{
font-family:ttt;
src: url(/static/font/simkai.ttf)
}這里的ttf是字體,位置放在static/font下,在html里可以直接用font-family:ttt;來引用;
2.就是這個文件dompdf\lib\fonts\dompdf_font_family_cache.php
如果遷移代碼的時候需要把這個刪掉,或者修改family的名稱。