Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124


Add custom font in dompdf in Laravel

In this tutorial, I will give you an example of “How to add custom font in dompdf in Laravel,” so you can easily apply it to your Laravel 5, Laravel 6, Laravel 7, Laravel 8, Laravel 9, and Laravel 10 applications.

issue fixed add-custom-font-in-dompdf-in-laravel

Need to add custom font in dompdf in Laravel

The barryvdh/laravel-dompdf package allows you to generate PDFs in Laravel using the Dompdf library. The need to add a custom font in dompdf in Laravel to customize fonts and add enhancements to pdf files.

There are multiple ways to add custom fonts in the Laravel Dompdf package. In this topic, I will share the easiest way to call a custom font in a PDF file in the Laravel application.

If you want to use custom fonts in your PDFs, you can follow this step:

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400;
  src: local('Montserrat-Regular'), url( format('truetype');
@font-face {
  font-family: 'Montserrat';
  font-style: bold;
  font-weight: 700;
  src: local('Montserrat-Bold'), url( format('truetype');
  <p style="font-family: Montserrat, serif; font-weight:semibold">Welcome To 8bityard</p>
  <p style="font-family: Montserrat, serif">8Bityard provides a collection of tutorials about programming PHP, Laravel Framework Mysql Database,
    Bootstrap Front-end Framework, WordPress, Jquery, Ajax Example, APIs, Composer Packages Example, React Js, etc. 
    So you can also search tutorials from the search box.</p>

Remember to clear your Laravel configuration cache after making changes to the configuration file.

php artisan config:cache