Thursday, March 16, 2017

DOMPDF not caching some fonts

I want to use 5 different fonts in my PDF (all of them TrueType). Yesterday I added one of them as @font-face and copied the file to /storage/fonts (I am using barryvdh/laravel-dompdf, so this is set by default). The .ufm was created and added to dompdf_font_family_cache.php, everything worked fine.

Today I wanted to add the rest of the fonts, I have made separate @font-face properties, copied the fonts but no .ufm files were created, so they can't be used in the PDF.

Google Fonts can be added without any problem, and they are getting cached!

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <style>
            @page {
                margin:0;
                padding:0;
            }
            @font-face {
                font-family: 'font1';
                src: url('/storage/fonts/font1.ttf') format('truetype');
                font-weight: normal;
                font-style: normal;
            }
            @font-face {
                font-family: 'font2';
                src: url('/storage/fonts/font2.ttf') format('truetype');
                font-weight: normal;
                font-style: normal;
            }
            .font1{
                text-align: center;
                font-family: 'font1', sans-serif;
            }
            .font2{
                font-family: 'font2', sans-serif;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div class="font1">This font is cached</div>
            <div class="font2">This font isn't</div>
        </div>
    </body>
</html>

I am on a local WAMP server (PHP 5.6.25), Laravel 5.3, DOMPDF 0.8 w/ laravel-dompdf.

What am I missing?



via Ozwald

Advertisement