在我的 Laravel 项目中,我使用 DOMPDF 从 html Blade 文件生成 pdf。我想根据语言选择显示印地语或古吉拉特语文本。这是我的控制器代码。
$pdf=PDF::loadView('my-htmlt.pdffile',['header'=>$header,'data'=>$data,'footer'=>$footer]);
$name=$header->name."_".date('YmdHis');
if(isset($view) && $view!=''){
return $pdf->stream($name.'.pdf');
} else {
return $pdf->download($name.'.pdf');
}
这是刀片文件中的代码。
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{$header->name}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<style type="text/css">
@page{
padding: 15px;
}
<?php if($header->lang== 'Guj'){ ?>
* {
font-family: 'noto serif gujarati', sans-serif;
}
<?php } else if($header->lang == 'Hindi'){ ?>
* {
font-family: 'tiro devanagari hindi', sans-serif;
}
<?php } ?>
</style>
<body>{{Content fetched from database either in Hindi or Gujarati}}</body>
</html>
I have downloaded ttf font files for Noto Serif Gujarati and Tiro Devnagari and copy under projectfolder/storage/fonts Folder. I have also tried using face font css with file path of ttf file. But result is same so, working with less code.
I have set collation and charset as utf8_unicode_ci in database and getting text properly from database, tested printing html view.
Now issue is that text is showing in Hindi or gujarati but text is not showing properly as per my requirement.
For example I want to show text like "ચિત્ર જોઈ તેનો પહેલો મૂળાક્ષર શોધો". But it is showing like this
Same way in hindi I want to show text like "कौन सा जीव धीमी गति से चलता है ?" But it is showing like this
谁能提供在 PDF 中显示正确文本的解决方案?