In my laravel project I am using DOMPDF to generate pdf from html blade file. I want to show text in Hindi or Gujarati as per language selection. Here is my code of controller.
$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');
}
Here is the code in blade file.
<!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
Can anyone have solution to show proper text in PDF?
So, After putting lot of efforts I have taken another option. I am rendering my view with
return view('my-html.pdffile',['header'=>$header,'data'=>$data,'footer'=>$footer]);
And in my-html.pdffile Blade file I am allowing user to download pdf with window.print script like this.
<script>
var is_chrome = function () { return Boolean(window.chrome); }
if(is_chrome){
window.print();
// setTimeout(function(){window.close();}, 10000);
// give them 10 seconds to print, then close
}else{
window.print();
}
</script>
Now I can download pdf as per my requirement with all the languages without using any fonts or downloading any font libraries.