我正在尝试在 Laravel 中创建的 PDF 中指定字体

I am trying to specify a font in a created PDF in Laravel

我正在使用 niklasravnsborg/laravel-pdf 在 Laravel 中创建 PDF 文件。我想使用 Arial 字体,但该字体不起作用。

$pdf = PDF::loadView('blade', $data, [], [
    'format' => 'A4-L',
    'orientation' => 'L'
]);

您可以CSS使用特定字体。

body {
    font-family: Arial, sans-serif;
}

我遇到了同样的问题。下面是它的精确解

$pdf = PDF::loadView('blade',$data, [], [
                     format' => 'A4-L',
                     'orientation' => 'L',
                     'mode' => 'c'
                    ]);

并且在 blade 文件中你应该需要添加在顶部

<style type="text/css">

    body {
        font-family: Arial, Helvetica, sans-serif;
    }
</style>