脚本宝典收集整理的这篇文章主要介绍了php – 中文字符的DomPDF生成,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
require('dompdf/dompdf_config.inc.PHP'); $dompdf = new DOMPDF(); mb_internal_encoding('UTF-8'); def("DOMPDF_UNICODE_ENABLED",true); $htML = ' <html> <head> <Meta http-equiv="Content-tyPE" content="text/html; charset=utf-8"/> <style> *{ font-family: DejaVu Sans,font-Size: 12px;} </style> </head> <body> 忠烈祠 </body> </html>'; $dompdf->load_html($html); $dompdf->render(); $output = $dompdf->output(); $filename = 'a.pdf'; $path = $filename; file_put_contents($path,$output);
问题是当我用chrome或adobe reader打开它时生成的PDF只显示正方形,但它在Mozilla Firefox中看起来没问题.
任何sugestions?
其次,你需要一个不同的字体. dompdf附带的DejaVu字体不支持CJK.有关概述,请阅读我对Dompdf and set different font-family的回答.
如果您当前没有字体,可以尝试查找Firefly Sung.无论您决定使用哪种字体,它都应该是TTF,以便dompdf使用它.
以下是通过@ font-face CSS规则使用Firefly Sung的示例,无需安装:
<!DOCTYPE html> <html> <head> <Meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style> @font-face { font-family: 'Firefly Sung'; font-style: normal; font-weight: 400; src: url(http://eclecticgeek.COM/dompdf/fonts/cjk/fireflysung.ttf) format('truetype'); } * { font-family: Firefly Sung,DejaVu Sans,sans-serif; } </style> </head> <body> <div>忠烈祠</div> </body> </html>
以上是脚本宝典为你收集整理的php – 中文字符的DomPDF生成全部内容,希望文章能够帮你解决php – 中文字符的DomPDF生成所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。