在 laravel 5.4 中使用 DomPdf 创建 PDF 时显示希伯来字符
Show Hebrew character during PDF creation with DomPdf in laravel 5.4
我很抱歉没有尝试任何事情。
我想在 Larave DOMPDF 创建的 PDF 中显示希伯来语字符。
我不知道该做什么以及如何实现。我做了一些搜索,但没有运气。
这就是我加载 PDF 文件的方式
PDF::loadView('pdf', ['leadInfo'=>$leadInfo,'leadByContinent'=>$leadByContinent,'leadByStatus'=>$leadByStatus])
->save(public_path().'/leadPdfs/'.$leadPdfName);
PDF blade 文件是
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<table class="lead" cellspacing="0" width="100%" style="font-size: 12px; font-family: 'Arial, Helvetica Neue, Helvetica, sans-serif';">
<thead>
<tr>
<th width="10%" style="font-weight: bold;">Date</th>
<th width="15%" style="font-weight: bold;">Name</th>
<th width="20%" style="font-weight: bold;">Details</th>
<th width="10%" style="font-weight: bold;">Contact Origin</th>
<th width="15%" style="font-weight: bold;">Status</th>
<th width="10%" style="font-weight: bold;">Comment</th>
<th width="10%" style="font-weight: bold;">Country</th>
</tr>
</thead>
<tbody>
<?php
foreach($leadInfo as $k=>$v){
$continent = getAllContinentName($v->country);
if(strtolower($continent) == strtolower("Asia")){
$backGround = "#FFB300";
} else if(strtolower($continent) == strtolower("Africa")){
$backGround = "#FFB300";
} else if(strtolower($continent) == strtolower("North America")){
$backGround = "#009792";
} else if(strtolower($continent) == strtolower("South America")){
$backGround = "#FF7E00";
} else if(strtolower($continent) == strtolower("Antarctica")){
$backGround = "#15E6E8";
} else if(strtolower($continent) == strtolower("Europe")){
$backGround = "#0074FF";
} else if(strtolower($continent) == strtolower("Australia")){
$backGround = "#05A900";
} else {
$backGround = "#FFFFFF";
}
if($v->email_status_id == 10){
$statusBackGround = "#a9d18d";
} else if($v->email_status_id == 11){
$statusBackGround = "#ff0000";
} else if($v->email_status_id == 12){
$statusBackGround = "#b3c6e7";
} else if($v->email_status_id == 13){
$statusBackGround = "#c09200";
} else if($v->email_status_id == 14){
$statusBackGround = "#ffff00";
} else {
$statusBackGround = "#FFFFFF";
}
?>
<tr>
<td> {{ Carbon\Carbon::parse($v->created_date)->formatLocalized('%d %b %Y') }} </td>
<td>{{ $v->name }}</td>
<td>{{ mb_substr($v->message, 0, 300) }}</td>
<td>{{ $v->contact_origin }}</td>
<td style="color:black; background-color: {{ $statusBackGround }}" >{{ $v->status_name }}</td>
<td>{{ $v->comment }}</td>
<td style="color:black; background-color: {{ $backGround }}" >{{ getAllCountryName($v->country) }}</td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
结果是
现在,它显示 ?????
而不是希伯来字符。
额外信息:数据库中的数据是希伯来语的,所以我只是获取它并将其放入 PDF blade 文件中。
如果有人对此提出任何建议,那就太好了。
我正在使用 Laravel 5.4。
我通过将 font-family
值替换为 firefly, DejaVu Sans, sans-serif
解决了这个问题,这在 https://github.com/dompdf/dompdf/wiki/UnicodeHowTo#load-a-font-supporting-your-characters-into-dompdf.
中有描述
因为 DejaVu 字体,支持范围广泛的字符。如果 DejaVu 字体不支持您文档中的字符,任何 TrueType 字体都可以使用。
我很抱歉没有尝试任何事情。
我想在 Larave DOMPDF 创建的 PDF 中显示希伯来语字符。
我不知道该做什么以及如何实现。我做了一些搜索,但没有运气。 这就是我加载 PDF 文件的方式
PDF::loadView('pdf', ['leadInfo'=>$leadInfo,'leadByContinent'=>$leadByContinent,'leadByStatus'=>$leadByStatus])
->save(public_path().'/leadPdfs/'.$leadPdfName);
PDF blade 文件是
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<table class="lead" cellspacing="0" width="100%" style="font-size: 12px; font-family: 'Arial, Helvetica Neue, Helvetica, sans-serif';">
<thead>
<tr>
<th width="10%" style="font-weight: bold;">Date</th>
<th width="15%" style="font-weight: bold;">Name</th>
<th width="20%" style="font-weight: bold;">Details</th>
<th width="10%" style="font-weight: bold;">Contact Origin</th>
<th width="15%" style="font-weight: bold;">Status</th>
<th width="10%" style="font-weight: bold;">Comment</th>
<th width="10%" style="font-weight: bold;">Country</th>
</tr>
</thead>
<tbody>
<?php
foreach($leadInfo as $k=>$v){
$continent = getAllContinentName($v->country);
if(strtolower($continent) == strtolower("Asia")){
$backGround = "#FFB300";
} else if(strtolower($continent) == strtolower("Africa")){
$backGround = "#FFB300";
} else if(strtolower($continent) == strtolower("North America")){
$backGround = "#009792";
} else if(strtolower($continent) == strtolower("South America")){
$backGround = "#FF7E00";
} else if(strtolower($continent) == strtolower("Antarctica")){
$backGround = "#15E6E8";
} else if(strtolower($continent) == strtolower("Europe")){
$backGround = "#0074FF";
} else if(strtolower($continent) == strtolower("Australia")){
$backGround = "#05A900";
} else {
$backGround = "#FFFFFF";
}
if($v->email_status_id == 10){
$statusBackGround = "#a9d18d";
} else if($v->email_status_id == 11){
$statusBackGround = "#ff0000";
} else if($v->email_status_id == 12){
$statusBackGround = "#b3c6e7";
} else if($v->email_status_id == 13){
$statusBackGround = "#c09200";
} else if($v->email_status_id == 14){
$statusBackGround = "#ffff00";
} else {
$statusBackGround = "#FFFFFF";
}
?>
<tr>
<td> {{ Carbon\Carbon::parse($v->created_date)->formatLocalized('%d %b %Y') }} </td>
<td>{{ $v->name }}</td>
<td>{{ mb_substr($v->message, 0, 300) }}</td>
<td>{{ $v->contact_origin }}</td>
<td style="color:black; background-color: {{ $statusBackGround }}" >{{ $v->status_name }}</td>
<td>{{ $v->comment }}</td>
<td style="color:black; background-color: {{ $backGround }}" >{{ getAllCountryName($v->country) }}</td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
</html>
结果是
现在,它显示 ?????
而不是希伯来字符。
额外信息:数据库中的数据是希伯来语的,所以我只是获取它并将其放入 PDF blade 文件中。
如果有人对此提出任何建议,那就太好了。
我正在使用 Laravel 5.4。
我通过将 font-family
值替换为 firefly, DejaVu Sans, sans-serif
解决了这个问题,这在 https://github.com/dompdf/dompdf/wiki/UnicodeHowTo#load-a-font-supporting-your-characters-into-dompdf.
因为 DejaVu 字体,支持范围广泛的字符。如果 DejaVu 字体不支持您文档中的字符,任何 TrueType 字体都可以使用。