I am using barryvdh/laravel-dompdf to load PDF's in my laravel application. I need to load custom unicode fonts(sinhala) in to the pdf. To do this, I downloaded my external fonts and copied the font folder and then it load to storage/fonts
directory by load_font.php.
I have used css in my blade file as follows:
@font-face {
font-family: Noto-2;
font-display: block;
src: url({{ asset('fonts/NotoSansSinhala-Light.ttf') }}) format("truetype");
}
body {
font-family: Noto-2 !important;
font-style: normal;
font-weight: 500;
font-size: 14px!important;
}
I also set meta tag UTF-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
HTML part:
<td class="td_cus" rowspan="5">
<span class="title">මික් ආහාර සේවය</span>
<p class="company_address">
2 වැනි මහළ,<br>
<span style="font-family: helvetica !important;">M I C </span>සුපර් සෙන්ටර්,<br>
මොරටුව,<br>
ශ්රී ලංකාව.
</p>
</td>
Laravel controller:
$path = Storage::disk('local')->path("letters(".$letterCount."-letters).pdf");
$pdf = PDF::loadview('templates.letterSinhala', ['details' => $details])
->setPaper('a4', 'portrait')
->save($path);
When I load my html page normally, the font works perfectly. However, when I am trying to load the font in the PDF, the font does not display correctly. Could somebody please guide me on how to load the font correctly.
On a normal page(HTML view), it shows as follows:
When I generate the PDF, it shows as follows:
NOTE: Please see upper two images, that can be easy to understand the issue;
The problem is sinhala text displaying incorrectly on PDF, but when i copy & paste that somewhere , the text show in correctly.
Any ideas on how I can solve this issue? Please help..