DomPDF generation for chinese characters

巧了我就是萌 提交于 2019-12-01 19:37:07
BrianS

First, move def("DOMPDF_UNICODE_ENABLED", true); above the require since the def function included with dompdf only defines the constant if it doesn't exist. When you include dompdf_config.inc.php that constant will be set at that time. Also, use define instead.

Second, you need a different font. The DejaVu fonts included with dompdf do not support CJK. For an overview read my answer to Dompdf and set different font-family.

If you do not currently have a font you might try looking up Firefly Sung. Whatever font you decide to use it should be TTF in order for dompdf to use it.

Here's an example using Firefly Sung via the @font-face CSS rule, no installation required:

<!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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!