Rakibul Islam
Rakibul Islam

Reputation: 687

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

Upvotes: 2

Views: 4219

Answers (2)

Honest Knight
Honest Knight

Reputation: 390

Sometimes it creates a lot of problems if you change on vendor folder. Especially if you want to update the plugin. So my solution is,

Add on config/pdf.php

return [
'custom_font_dir'  => base_path('resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
    'solaimanlipi' => [ // must be lowercase and snake_case
        'R'  => 'SolaimanLipi-Regular.ttf',    // regular font
        'B'  => 'SolaimanLipi-Bold.ttf',       // optional: bold font
        'I'  => 'SolaimanLipi-Italic.ttf',     // optional: italic font
        'BI' => 'SolaimanLipi-Bold-Italic.ttf' // optional: bold-italic font
    ]
  // ...add as many as you want.
]];

Now add the css on the view file

body {font-family: 'solaimanlipi', sans-serif;}

Upvotes: 1

Kalyan Halder
Kalyan Halder

Reputation: 1585

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.

Upvotes: 4

Related Questions