我在MPDF库中使用UTF-8字符集时遇到问题

问题描述 投票:0回答:1

我正在制作一个自动生成合同的系统,问题是我无法打印PDF中的某些字符。

Srgio Avilla(例如,我的名字是这样)->它应该像这样出来:SérgioAvilla。

下面是简化的应用程序代码。

<?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下来的。

php pdf utf-8 character-encoding mpdf
1个回答
0
投票

在合同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">

© www.soinside.com 2019 - 2024. All rights reserved.