Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chandy's avatar

Add custom fonts to barryvdh/laravel-dompdf

I need to use custom fonts that i have downloaded from google web fonts, i have already created a folder under /app/storage called fonts, i have tried using the fonts in my pdf file but they are not appearing.

<!DOCTYPE html>
  <html>

  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' 
  name='viewport'>
<title>Courses Report</title>
<style type="text/css">

    @font-face {
        font-family: 'Lato-Italic';
        src: url('Lato-BoldItalic.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    @font-face {
        font-family: 'Lobster';
        src: url('Lobster-Regular.ttf') format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    @font-face {
        font-family: 'Vibes';
        src: url("https://fonts.googleapis.com/css?family=Great+Vibes") format('truetype');
        font-weight: normal;
        font-style: normal;
    }

 </style>

0 likes
5 replies
neilherbertuk's avatar

I have no knowledge of barryvdh/laravel-dompdf, however, based on your code; you aren't telling it where to find the fonts. Your code is looking for the fonts relative to however it's being called. It has no idea that your fonts are in the /app/storage/fonts folder, even if that is accessible to it.

Neil

1 like
chandy's avatar

@neilherbertuk after i run the php artisan vendor:publish command for barryvdh/laravel-dompdf a dompdf.php file is created in the /config directory. in that file there is a place you specify the fonts directory.

which package do you use to generate PDF files?

neilherbertuk's avatar

Have you tried putting the fonts in the public/fonts folder? Give that ago and change your CSS so each font's src is pointing at /fonts/fontfile.ttf

TheJourneyman's avatar

@jewelhuq Don't forget that sometimes it needs manually update the file dompdf_font_family_cache.dist.php with the new array element.

Please or to participate in this conversation.