Laravel DomPDF Google fonts not loading

Viewed 4998

Trying to use Google Fonts with Laravel DomPDF 0.7.* but I'm having a hard time getting them to show. In fact I can't get any custom fonts to work, not just Google Fonts.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="https://fonts.googleapis.com/css?family=Caveat" rel="stylesheet">
        <style type="text/css">

            .signature {
                font-family: 'Caveat', cursive !important;
                font-size: 30px;
            }
        </style>
    </head>

    <body>
        <p class="signature">Name</p>
    </body>
</html>

This is what shows up, it's supposed to be a handwriting font.

enter image description here

In dompdf.php config file, the font dir and font cache are both writeable.

"DOMPDF_FONT_DIR" => storage_path('app/tmp/'), 
"DOMPDF_FONT_CACHE" => storage_path('app/tmp/'),

Here is the controller code:

public function download(Request $request, string $contractKey)
{
    $item = Item::findOrFail($contractKey);

    $body = @$item->contract;

    $pdf = PDF::loadView('pdf.contract', [
        'body'  => $this->cleanContract($body),
        'docId' => md5($item->id),
        'item'  => $item,
        'ip'    => $ip = @$request->ips()[1] ?: $request->ip(),
    ]);

    $pdf->output();
    $dom_pdf = $pdf->getDomPDF();

    $canvas = $dom_pdf->get_canvas();
    $canvas->page_text($canvas->get_width() - 70, $canvas->get_height() - 30, "Page {PAGE_NUM} of {PAGE_COUNT}", null, 10, [0, 0, 0]);


    return $pdf->stream();
}
1 Answers
Related