LaravelDaily / laravel-invoices

Laravel package to generate PDF invoices from various customizable parameters
GNU General Public License v3.0
1.39k stars 303 forks source link

Custom font #132

Closed srocerer closed 2 years ago

srocerer commented 2 years ago

How to add custom font to the invoice I have tried different ways, different font types but none of them worked. In HTML view everything looks good but after changing the method to download invoice text looks missing.

Example font import:

@font-face {
    font-family: 'Inter';
    font-weight: 400;
    font-style: normal;
    font-variant: normal;
    src: local('Inter'), url({{ storage_path('fonts/inter/Inter-Regular.otf') }}) format('truetype');
}

@font-face {
    font-family: 'Inter';
    font-weight: 700;
    font-style:normal;
    font-variant:normal;
    src: local('Inter'), url({{ storage_path('fonts/inter/Inter-Bold.otf') }}) format('truetype');
}

body {
    font-family: 'Inter', sans-serif;
    font-weight: 400;
}
mc0de commented 2 years ago

@srocevas for custom font please refer to DomPDF https://github.com/dompdf/dompdf/issues?q=is%3Aissue+custom+font package, because it responsible for PDF rendering. Laravel Invoices wraps all invoice functionality around it.

dodaydream commented 2 years ago

I also have the same issue before. And I would also say this wasn't the issue of this library. However, since Laravel Invoices relies on laravel-dompdf, which wraps the DomPDF library. It seems calling the setOptions method in laravel-dompdf will override the whole settings to DomPDF's default instead of laravel-dompdf's default...

Therefore, even the font directory of laravel-dompdf is set to /storage/fonts. It will reverted to DomPdf's default (i.e. in /vendor/dompdf/dompdf/fonts) once the setOptions has been called (Laravel Invoices use this method to render page number). This results DomPDF unable to find your custom font.

I have already created a pull request on laravel-dompdf (see: https://github.com/barryvdh/laravel-dompdf/pull/846) to fix this and waiting for their approval.