我将 Laravel 5.5 与 DOMPDF 一起使用,它对英语工作正常,但不适用于 Unicode,它总是输出 ????
我的象征
Controller
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');
}
}
Blade
<!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>
结果
?????????
最佳答案
@计划-B
我使用这个包,它的工作方式与此相同 Dompdf-Laravel
库( Dompdf-Laravel
库适用于其他语言,但不适用于高棉字体)。
composer require niklasravnsborg/laravel-pdf
php artisan vendor:publish
从命令提示符选择库。您将获得 pdf.php
在 config
目录config/pdf.php
选择 resources/fonts
目录这是我在
pdf.php
中的设置// some code here...
'font_path' => base_path('resources/fonts/'),
'font_data' => [
"khmerosmoul" => [/* Khmer */
'R' => "KhmerOSmuol.ttf",
'useOTL' => 0xFF,
],
"khmerosmoullight" => [/* Khmer */
'R' => "KhmerOSmuollight.ttf",
'useOTL' => 0xFF,
],
"khmerosbokor" => [/* Khmer */
'R' => "KhmerOSBokor.ttf",
'useOTL' => 0xFF,
],
"khmerosmoulpali" => [/* Khmer */
'R' => "KhmerOSmuolpali.ttf",
'useOTL' => 0xFF,
'useKashida' => 75
]
// ...add as many as you want.
]
注意:您可能会遇到 pdf html 结构的问题。从 repo 复制其模板示例并根据需要重新设计。
https://github.com/niklasravnsborg/laravel-pdf/blob/master/tests/views/exposify-expose.html
关于php - Dompdf-Laravel 不能使用 Unicode 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48676957/