Search code examples
laraveldompdfdevanagari

How to write devanagari script in the dompdf?


I have devanagari script in my html file. But it is displayed as ?????? in the .pdf file. how to solve this problem?

This is the html code

<style>
  @font-face {
    src: url("/Shivaji01.ttf");
    font-family: "Shivaji01";
  }
</style>

<p style="text-align:center;font-family:Shivaji01"> फोंडा - गोवा 403401 </p>

and i am getting this error: Undefined index:in \vendor\dompdf\dompdf\lib\Cpdf.php


Solution

  • step 1) add your font's ttf(TrueType font),afm(Adobe Font Metrics) and ufm types in your vendor/dompdf/lib/fonts file.

    step2) edit your "dompdf_font_family_cache.dist.php" file. add

    'yourFontName' =>
            array(
                'bold' => $distFontDir . 'yourFontName',
                'bold_italic' => $distFontDir . 'yourFontName',
                'italic' => $distFontDir . 'yourFontName',
                'normal' => $distFontDir . 'yourFontName',
            ),
    

    step 3) in your css, add

    @font-face {
                src: url("/PathToyourFont.ttf");
                font-family: "yourFontName";
     } 
    

    step 4) in your css, you can use your font inside font-family

    body {
             margin-right: 1cm;
             margin-left: 1cm;
             font-family: "yourFontNamr",Helvetica,Arial,sans-serif;
          }