How to write devanagari script in the dompdf?

544 Views Asked by At

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

2

There are 2 best solutions below

0
Rhugveda Desai On BEST ANSWER

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;
      }
0
Merlin Roth On

Are you using the utf8? Which font did you choose? Make sure that the font contains the characters and the document is in the correct encoding.

I hope this helps: dompdf character encoding UTF-8