Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

add-custom-font-in-dompdf-in-laravel

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.

add-custom-font-in-dompdf-in-laravel
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:

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 400;
  src: local('Montserrat-Regular'), url(https://fonts.gstatic.com/s/montserrat/v6/zhcz-_WihjSQC0oHJ9TCYC3USBnSvpkopQaUR-2r7iU.ttf) format('truetype');
}
@font-face {
  font-family: 'Montserrat';
  font-style: bold;
  font-weight: 700;
  src: local('Montserrat-Bold'), url(https://fonts.gstatic.com/s/montserrat/v6/IQHow_FEYlDC4Gzy_m8fcvEr6Hm6RMS0v1dtXsGir4g.ttf) format('truetype');
}
</style>
</head>
<body>
  <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>
</body>
</html>

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

php artisan config:cache