# 安装字体,解决中文乱码
参考: https://blog.51cto.com/lampzxr/1916038
```
首先下载composer curl -sS https://getcomposer.org/installer | php 下载dompdf包 php composer require dompdf/dompdf 下载load_font.php,此文件的功能是安装中文字体 1.git clone https://github.com/dompdf/utils.git 2. 复制 load_font.php到 dompdf目录中,与lib 和 src 目录同级。 下载中文字体,推荐下载 Droid Sans Fallback 字体,也可用雅黑字体,【雅黑字体会导致导出文档过大】 下载链接【http://www.17ziti.com/info/71250.html】 安装字体,将字体传到服务器目录下,运行load_font.php php load_font.php 'Droid' /data/DroidSansFallback.ttf。 运行后,若没报错,则在 vendor/dompdf/dompdf/lib/fonts/下生了 Droid.ttf,Droid.ufm 这两个文件。 在PHP代码中设置中文字体
<?php
require 'vendor/autoload.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$html=
<<<HTML
<html>
<head>
</head>
<body>
<!-- font-family:yahei; china-->
<div style="font-family:Droid; color: #f00;font-size: 14px"> 中文123 </div>
</body>
</html>
HTML;
$html = iconv('gb2312','utf-8',$html);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
$dompdf->stream();
注意 CSS 样式中的 font-family 设置为 之前运行load_font.php中设置的字体名。
``` # 解决中文换行问题
修改文件: dompdf/dompdf/src/FrameReflower/Text.php
找到关键字: // split the text into words
```php
$words = preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
$wc = count($words);
```
修改为
```php
preg_match_all('/./u', $text, $array);
$words = $array[0];
$wc = count($words);
```

最新文章

  1. Android Hook 借助Xposed
  2. C# 构造post参数一种看起来直观点的方法[转]
  3. ajax传递数组到后台
  4. C# 代码示例_结构/数组/枚举...
  5. 项目跑起来之后,一会儿后台就会报错Illegal access: this web application instance has been stopped already. Could not load [com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask]. The following stack trace
  6. ulipad 常用快捷键
  7. web旋转式
  8. [转载]传智播客_SQL入门
  9. 一张图讲解为什么需要自己搭建自己的git服务以及搭建的途径
  10. 有关XCode6(iOS8)UITableViewCell与iOS7在UITableViewCell问题
  11. java中try 与catch的使用
  12. vue中什么样的数据可以是在视图中显示
  13. Android必知必会-Handler可能引起的内存泄露
  14. Yii1操作phpexcel
  15. Hibernate学习(八)———— Hibernate检索策略(类级别,关联级别,批量检索)详解
  16. pandas-cheat-sheet
  17. folly无锁队列,尝试添加新的函数
  18. Spring boot项目集成Sharding Jdbc
  19. Long与long的区别
  20. 7. I/O复用

热门文章

  1. blockingqueue.h
  2. python老师博客
  3. (0)开始 Raspberry Pi 项目前需要知道的 10 件事
  4. 小程序&app 注册登录、绑定
  5. 洛谷 P3243 [HNOI2015]菜肴制作 题解
  6. bzoj 3992: [SDOI2015]序列统计 NTT+原根
  7. thymeleaf做if判定
  8. su与su -,sudo 的区别
  9. %lld 和 %I64d
  10. Mongoose 内置 CURD 方 法、扩展 Mongoose Model 的静态方法和 实例方法