Search code examples
laravelfontsmpdf

Bangla unicode fonts not displaying in mpdf


I am using mpdf to generate pdf. While the document contains bangla unicode fonts it is invisible in pdf document.

I have included the fonts properly in config/pdf.php

'bangla' => [
            'R'  => 'SolaimanLipi.ttf', // regular font
            'B'  => 'SolaimanLipi.ttf', // optional: bold font
            'I'  => 'SolaimanLipi.ttf', // optional: italic font
            'BI' => 'SolaimanLipi.ttf', // optional: bold-italic font
            'useOTL' => 0xFF,   
            'useKashida' => 75, 
        ]

CSS Style of rendering bangla text

.textLayer > div {
color: transparent;
white-space: pre;
cursor: text;
transform-origin: 0% 0%;
}

while i change the color it displays a duplicate text.

Output


Solution

  • Your configuration is correct. Please make sure you have the font file inside ttfonts folder. Then in your html file you write like this

        html, body, div {
          font-family: bangla;
        }
    

    I used font-family name bangla because you configured it here,

    'bangla' => [
            'R'  => 'SolaimanLipi.ttf', // regular font
            'B'  => 'SolaimanLipi.ttf',
            ..........
            'useOTL' => 0xFF,
            'useKashida' => 75]
    

    Now You should call mPDF like this,

    $mpdf = new \Mpdf\Mpdf([
                'default_font' => 'bangla',
                'mode' => 'utf-8'
            ]);
    

    Now In your case, for css call like this,

    .textLayer > div {
       font-family: bangla;
       color: transparent;
       white-space: pre;
       cursor: text;
       transform-origin: 0% 0%;
     }
    

    It should work.