1

I have used Hindi font in my laravel project for generating pdf using dompdf. I have downloaded Noto Sans Devanagari font and place under myproject\storage\fonts folder.

I have used in blade html file like this.

<style>
 * { font-family: Noto Sans, sans-serif; }  
</style>

I have set collation and charset as utf8_unicode_ci in database table column structure and also in config/database.php like this.

'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'test'),
        'username' => env('DB_USERNAME', 'test'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => false,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

Now when I generate pdf with hindi language, it is showing perfectly, Now I have added Noto sans gujarati in same fonts folder and modify my view file like this.

<style>
 * { 
  font-family: 'Noto Sans Devanagari', sans-serif; 
  font-family: 'Noto Sans Gujarati', sans-serif;
  } 
</style>

But Gujarati font is not showing properly either it shows boxes or ?? I have also tried including google font library like this.

<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Devanagari:wght@300&family=Noto+Sans+Gujarati:wght@300&display=swap" rel="stylesheet">

Can anyone suggest me how can gujarati and hindi font we can show in pdf?

Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
Maya Shah
  • 950
  • 7
  • 17
  • So, I have figure it out and using single font family at one time. As I have one object which returns font type I need to use. So, now it's working fine with Hindi Or Gujarati. – Maya Shah May 17 '23 at 06:07
  • So, Now getting new challenge bcaz gujarati text is not showing properly. So, creating new question. – Maya Shah May 26 '23 at 04:37
  • https://stackoverflow.com/questions/76337822/dompdf-gujarati-and-hindi-text-not-showing-properly – Maya Shah May 26 '23 at 05:12

2 Answers2

0

Create a new fonts folder at the project root. How to set different font-family in Dompdf

Copy your fonts which you want to use in your pdf to the fonts folder. I have copied OpenSans-Regular.ttf and OpenSans-Bold.ttf to the folder.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 15 '23 at 09:31
0

As I know, you can't use two fonts in the root. CSS doesn't support that way. You have to try quite a similar approach to archive this.

<style>
    .hindi { 
        font-family: 'Noto Sans Devanagari', sans-serif; 
    }
    .gujarati { 
        font-family: 'Noto Sans Gujarati', sans-serif;
    } 
</style>

<div class="hindi">
    Hindi text here
</div>

<div class="gujarati">
    Gujarati text here
</div>
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85