DEV Community

Shubham Raturi
Shubham Raturi

Posted on

Add Custom Font In Laravel DomPDF

From a year there is question in stackover flow, developer having a trouble to add custom or paid font in dompdf laravel,
The fonts showing in HTML view but not included in PDF.
I have face the same issue and added this to help others.

     **DomPDF provide a method to setOption**
Enter fullscreen mode Exit fullscreen mode

here is an code example.
$pdf = PDF::loadView('promo-template.pdf', compact('data'))
->setOption('fontDir', public_path('/fonts'));

In this code i have use setOption function with two agruments . (Option, value),
I have set option as a font Directory, and value would be the path of you want to set for fonts.

It will setup compile your font pdf html UTF-8 and genrate a json file for font to be included in PDF.

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more