Dompdf-Laravel 不能使用 Unicode 字符

Pla*_*n-B 6 php laravel

我将 Laravel 5.5 与 DOMPDF 一起使用,它适用于英语但不适用于 Unicode 它总是????向我输出符号

控制器

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use PDF;

class PdfController extends Controller
{
    public function export(){
        $data['title']="Print Report";
        $pdf = PDF::loadView('pdf.invoice', $data);
        return $pdf->download('invoice.pdf');
    }
}
Run Code Online (Sandbox Code Playgroud)

刀刃

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        @font-face {
            font-family: khmer;
            font-style: normal;
            font-weight: 400;
            src: url({{asset('fonts/khmer.ttf')}}) format('true-type');
        }
    </style>

</head>
<body>
    ????????????
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

结果 ?????????

小智 5

你只需要添加字体系列:DejaVu Sans;在你的正文中,或者你也可以将字体系列设置为要在其中显示 Unicode 字符的任何特定 div。

对于身体: body{font-family: DejaVu Sans;}

对于特定的 div: <div style="font-family: DejaVu Sans;"> --- </div>

希望这会有所帮助。


小智 0

我试图在我的应用程序中解决类似的问题,我所做的是使用mb_convert_encoding函数转换视图。

在你的情况下,我会这样:

    $data['title']="Print Report";
    $pdf = mb_convert_encoding(\View::make('pdf.invoice', $data), 'HTML-ENTITIES', 'UTF-8'));
    return PDF::loadHtml($pdf)->download('invoice.pdf');
Run Code Online (Sandbox Code Playgroud)

还要注意字体设置。您需要支持 UTF-8 字符集。