溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

php dompdf中文亂碼如何解決

發(fā)布時間:2023-02-02 10:21:19 來源:億速云 閱讀:234 作者:iii 欄目:編程語言

本篇內容主要講解“php dompdf中文亂碼如何解決”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“php dompdf中文亂碼如何解決”吧!

php dompdf中文亂碼的解決辦法:1、打開前端文件;2、通過設置“@font-face {font-family:ttt;src: url(/static/font/simkai.ttf)}”引用中文字體;3、刪除“dompdf_font_family_cache.php”即可。

php導出pdf,dompdf中文字體亂碼解決辦法(特別是代碼遷移引起的亂碼)

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;

結果:

php dompdf中文亂碼如何解決

需要說明:

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

php dompdf中文亂碼如何解決

如果遷移代碼的時候需要把這個刪掉,或者修改family的名稱。

到此,相信大家對“php dompdf中文亂碼如何解決”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續(xù)學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI