Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel DomPdf Add Custom Font

I am trying to use OLD English font in Dompdf with Laravel., I have inserted the font in laravel view. But it seems when generating the pdf It is not working.I tried editing dompdf >vendor >.../dompdf_font_family_cache.dist.php File.But no luck,

Can anyone Suggest a Solution?

Thanks In Advance.

like image 556
maxasela Avatar asked Apr 26 '17 13:04

maxasela


People also ask

How do I add fonts to laravel?

First, choose your fonts on fonts.google.com and grab the CSS URL. Next, install the package and publish the config file. Paste the CSS URL in the default font set. Finally, use the @googlefonts Blade directive in your layout file to load them.


1 Answers

  1. Make a fonts directory in the storage folder of your Laravel project. ( storage/fonts )
  2. Put your .otf or .ttf files in the storage/fonts directory.
  3. In your view/html add @font-face rules by using the storage_path method Laravel provides.

    @font-face {
        font-family: 'Your custom font name';
        src: url({{ storage_path('fonts\your-custom-font.ttf') }}) format("truetype");
        font-weight: 400; // use the matching font-weight here ( 100, 200, 300, 400, etc).
        font-style: normal; // use the matching font-style here
    }
    
  4. Add font-family rules to your css as seen below

    body {
        font-family: "Your custom font name";
    }
    

Hope this helps.

like image 154
Melvin Tehubijuluw Avatar answered Oct 01 '22 01:10

Melvin Tehubijuluw