简体   繁体   English

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

[英]How can I customize font and page in laravel dompdf?

I get from here : https://github.com/barryvdh/laravel-dompdf 我从这里得到: https : //github.com/barryvdh/laravel-dompdf

My controller is like this : 我的控制器是这样的:

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

My view is like this : 我的看法是这样的:

<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>

I use this : 我用这个:

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

When executed, the font is not Arial and the page is not display. 执行时,字体不是Arial,并且不会显示页面。

How can I solve it? 我该如何解决?

try in laravel 5.5 above . 试试上面的laravel 5.5

1.first download the font which u want to add(or set) as .ttf extenstion 1.首先下载要添加(或设置)为.ttf扩展名的字体

2.store inside laravel storage folder like this storage/fonts/yourfont.ttf 2.在laravel存储文件夹中存储这样的storage/fonts/yourfont.ttf

3.Use CSS @font-face rules inside your blade.. 3.在刀片内使用CSS @ font-face规则。

4.for example create sample.blade.php file like this 4.例如创建像这样的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM