如何在laravel dompdf中自定义字体和页面?

问题描述 投票:0回答:1

我从这里开始:https://github.com/barryvdh/laravel-dompdf

我的控制器是这样的:

public function listdata()
{
    $pdf=PDF::loadView('print_tests.test_pdf');
    $pdf->setPaper('L', 'landscape');
    return $pdf->stream('test_pdf.pdf');
}

我的观点是这样的:

<script type="text/php">

    if ( isset($pdf) ) {
        $x = 72;
        $y = 18;
        $text = "{PAGE_NUM} of {PAGE_COUNT}";
        $font = $fontMetrics->get_font("Arial", "bold");
        $size = 6;
        $color = array(0,0,0);
        $word_space = 0.0;  //  default
        $char_space = 0.0;  //  default
        $angle = 0.0;   //  default
        $pdf->page_text($x, $y, $text, $font, $size, $color, $word_space, $char_space, $angle);
    }

</script>

我用这个:

“barryvdh / laravel-dompdf”:“^ 0.7.0”,

执行时,字体不是Arial,页面不显示。

我该如何解决?

php laravel pdf laravel-5.3 dompdf
1个回答
2
投票

尝试上面的laravel 5.5。

1.首先下载要添加(或设置)为.ttf扩展的字体

2.存储在像lazvel存储文件夹里面这样的storage/fonts/yourfont.ttf

3.在刀片中使用CSS @ font-face规则..

例如,像这样创建sample.blade.php文件

<html>
<head>
    <meta http-equiv="Content-Type" content="charset=utf-8" />
    <style type="text/css">
        @font-face {
            font-family: 'yourfont'; //you can set your custom name also here..
            src: url({{ storage_path('fonts/yourfont.ttf') }}) format('truetype');
            font-weight: 400; // use the matching font-weight here ( 100, 200, 300, 400, etc).
            font-style: normal; // use the matching font-style here
         }        
        body{
            font-family: "yourfont",  //set your font name u can set custom font name also which u set in @font-face css rule
    </style>
</head>
<body>
    Check your font is working or not...
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.