Laravel dompdf 不显示日文字符
Laravel dompdf not showing japanese characters
我正在为 dompdf 使用 Laravel 5.4 和 barryvdh/laravel-dompdf 插件。我正在使用这段代码,
控制器
$pdf = PDF::loadView('invoice');
查看 (invoice.blade.php)
<!DOCTYPE html>
<html>
<head>
<title>Invoice</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>빨간색</div>
</body>
</html>
使用此代码时,日语文本将无法正确显示。我该如何解决这个问题?
您可以使用 this link 作为答案。它是日文的,但你可以使用 google chrome 翻译。
总结:
- 从 http://ipafont.ipa.go.jp/old/ipafont/download.html 下载字体文件或使用您想要的任何 ttf 文件
- 将 load_font.php 文件从 https://github.com/dompdf/utils 下载到 /vendor/dompdf/dompdf/
- 执行
#php load_font.php ipag $path_to_font_directory/ipag.tt
会生成类似 的东西
Unable to find bold face file.
Unable to find italic face file.
Unable to find bold_italic face file.
Copying $path_to_font_directory/ ipag.ttf to $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag.ttf...
Generating Adobe Font Metrics for $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag...
- 复制字体文件到存储#cp lib/fonts/* /storage/fonts/
- 在 css
中引用您的字体
body {
font-family: ipag;
}
我正在为 dompdf 使用 Laravel 5.4 和 barryvdh/laravel-dompdf 插件。我正在使用这段代码,
控制器
$pdf = PDF::loadView('invoice');
查看 (invoice.blade.php)
<!DOCTYPE html>
<html>
<head>
<title>Invoice</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div>빨간색</div>
</body>
</html>
使用此代码时,日语文本将无法正确显示。我该如何解决这个问题?
您可以使用 this link 作为答案。它是日文的,但你可以使用 google chrome 翻译。
总结:
- 从 http://ipafont.ipa.go.jp/old/ipafont/download.html 下载字体文件或使用您想要的任何 ttf 文件
- 将 load_font.php 文件从 https://github.com/dompdf/utils 下载到 /vendor/dompdf/dompdf/
- 执行
#php load_font.php ipag $path_to_font_directory/ipag.tt
会生成类似 的东西
Unable to find bold face file.
Unable to find italic face file.
Unable to find bold_italic face file.
Copying $path_to_font_directory/ ipag.ttf to $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag.ttf...
Generating Adobe Font Metrics for $laravel_install_directory /vendor/dompdf/dompdf/lib/fonts/ipag...
- 复制字体文件到存储#cp lib/fonts/* /storage/fonts/
- 在 css 中引用您的字体
body {
font-family: ipag;
}