0
votes

When using dompdf library for generating html to pdf i don't find any problem. But when i adding the @font-face in the CSS and providing the .ttf file for "Courier New" Font, the dompdf was stuck at some process and it won't finish generating the pdf file.

i'm adding this line to my style

@font-face { font-family: 'CourierNew'; src: url('{{ asset('fonts/cour.ttf') }}'); }

and i'm putting the Courier New TrueType file at the public/fonts/ folder

My Project using :

  1. Laravel : 5.8
  2. PHP : 7.3.11
  3. barryvdh/laravel-dompdf : ^0.8.4

Did anyone encounter such a problem or have a solution regarding this problem?

Thank you in advance.

Capture

2
Try using the path instead url src: {{ public_path('fonts/cour.ttf') }} ;porloscerros Ψ
@porloscerrosΨ i've try it before, even i try making it to a .css file and adding it using link in the head tag. Still no any luck. Btw the TrueType file was loaded when i load it as normal html but when i generate the pdf, the dompdf was stuck.Fradia
maybe it's you are ussing quotes, since {{ asset('fonts/cour.ttf') }} and {{ public_path('fonts/cour.ttf') }} are already strings. I used this aproach and work fine for me. And maybe you have to set a caching folder to dompdf as Helioarch mentioned github.com/barryvdh/laravel-dompdf/issues/….porloscerros Ψ

2 Answers

0
votes

You should try to temporarily increase the maximum execution with

ini_set('max_execution_time', 300);

// your pdf generation code

ini_restore('max_execution_time');

just to make sure that the issue is not that the pdf file you are trying to generate is too big and that the added time to load the font is enough to bring it over the execution time limit.

0
votes

This maybe late, Hope this one works for someone. My font files are in public/fonts/ I integrated with Laravel Blade and within that file in style tag you simply add the path as in normal css. And you also need to define the format, I got my font working like

@font-face {
        font-family: 'Product Sans';
        src: url('../fonts/ProductSans-Regular.ttf') format('truetype'),
        font-weight: normal;
        font-style: normal;
        font-display: swap;
    }