php - 我在 MPDF 库中遇到 UTF-8 字符集问题
问题描述
我正在制作一个自动生成合同的系统,问题是我无法打印 PDF 中的某些字符。
Sérgio Avilla(例如,我的名字是这样的)-> 它应该是这样的:Sérgio Avilla。
下面是简化的应用程序代码。
<?php
require_once __DIR__ . '/vendor/autoload.php';
include 'config.php';
header("Content-type: text/html; charset=utf-8");
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8', mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
$html = file_get_contents_utf8("contratos/".$contrato);
$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();
?>
如果有人可以帮助我,我将不胜感激。我已经测试过了,$html,如果直接打印在屏幕上没有问题,字符都对,问题是mpdf下来了。
解决方案
在合同 html 文件中有一个 charset =... 元标记,我只是将其更改为 charset = utf-8 并且它有效。
后:<meta http-equiv=Content-Type content="text/html; charset=utf-8">
前:<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
推荐阅读
- python - 在 macOS 上使用 pyenv 安装 python 3.8 失败
- javascript - 使用 API 数据映射渲染 React 组件;“未定义”错误
- r - gw_idf 给出的输出维度与文档中所述不同
- typescript - Svelte 3,如果我使用响应式语句,为什么不能访问这个 javascript 对象属性?
- event-handling - Hazelcast LifecycleListener stateChanged 从不触发
- python - 如何迭代 azure.core.paging.ItemPaged?
- esp8266 - 用 ESP-NOW 用 Blynk 控制 esp8266,有可能吗?
- python - 使用管道创建和附加 pandas 虚拟变量
- java - JPA Projections 过滤掉具有空外键的行
- jquery - 如何修复此 jQuery 以在滚动时获取鼠标位置并使我的 div 平滑地跟随我的光标?