如何在laravel dompdf中自定义字体和页面? [英] How can I customize font and page in laravel dompdf?

查看:416
本文介绍了如何在laravel dompdf中自定义字体和页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这里得到: 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",

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

执行后,该字体不是Arial字体,也不会显示该页面.

When executed, the font is not Arial and the page is not display.

我该如何解决?

推荐答案

在上述 laravel 5.5 中尝试.

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

1.first download the font which u want to add(or set) as .ttf extenstion

2.store像这样storage/fonts/yourfont.ttf

2.store inside laravel storage folder like this storage/fonts/yourfont.ttf

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

3.Use CSS @font-face rules inside your blade..

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

4.for example create sample.blade.php file like this

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

这篇关于如何在laravel dompdf中自定义字体和页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆