Laravel在dompdf中添加添加字体

时间:2017-08-04 10:32:12

标签: laravel pdf fonts dompdf

请给我回答,我如何在dompdf加载视图中添加外部字体:) 这是我的结构`

存储/ fonts /中存在Fonts文件夹,并且存在字体 供应商/ DOMPDF / DOMPDF / lib目录/字体/ 这是我的代码`

这是我的控制器

public function generatePdf($data)
{
    $data = Profile::find($data);

    $pdf = App::make('dompdf.wrapper');
    $pdf->setOptions(['fontDir' => storage_path('fonts/'), 'defaultFont' => 
    'OpenSansCondensedBold, OpenSans']);

    if ($data->graph_type == 'vertical') {
        $pdf->loadView('pdf.view', compact('data'));
    } else {
        $pdf->loadView('pdf.view', compact('data'))->setPaper('a4', 
        'landscape')->setWarnings(false)->output();
    }
    return $pdf->download();
}

查看` 标签中的文本是我的pdf视图的css代码 标签中的文字是我的html标签

<html lang="en">
<head>
    <style>
        h3{
            //font-family: "OpenSansCondensedBold";
            color: #7c5337;
            font-size: 18px;
            line-height: 18px;
            margin: 30px 0 0 0;
            padding: 0;
        }

        span{
            //font-family: "OpenSans";
            color: #484444;
            font-size: 14px;
            line-height: 14px;
            margin: 14px 0 0 0;
            padding: 0;
        }
        h2{
            //font-family: "OpenSans";
            color: #484444;
            font-size: 30px;
            line-height: 21px;
            padding: 0;
        }
        small{
            color: #7c5337;
            font-size: 14px;
            margin: 0 0 5px 0;
        }

        .left-block{
            float: left;
            padding-top: 200px;
            margin-left: 5%;
        }

        .left-block .image-block img{
            max-width: 173px;
            max-height: 526px;
        }
        .right-block {
            float: right;
            width: 40%;
            margin-left: 6%;
        }


        .topSection{
            width:80%;
            margin:  0 auto;
            text-align: center;
        }
        .info-block {
            padding:30px;
            margin-top: 20px;
            border: 1px solid #775035;
            border-radius: 10px;
            height: 560px;
            text-align: left;
        }
        .tiknesWidth li{
            color: #775035;
            text-decoration: none;
            list-style: none;
            display: inline-block;
        }


    </style>
</head>
<body>
    <div class="left-block">
        <div class="image-block">
            <?php if (is_null($data->file_pdf) || empty($data->file_pdf)) { 
            ?>
                <img class="ak-image-responsive" src="
                {{url('/user/images/not-image.png')}}">
            <?php } else { ?>
                <img class="ak-image-responsive" src="
                {{asset('/storage/product/pdf/'.$data->file_pdf)}}" >
            <?php } ?>
        </div>
    </div>

    <div class="right-block">
        <div class="topSection">
            <img src="{{url('/user/images/site-logo.png')}}"><br><br><br>
            <div class="text-block">
                <small>9407 Brown Lane #2</small><br>
                <small>Austin, Texas 78754</small><br>
                <small>P: 512-836-8990 office</small><br>
                <small>F: 512-836-9796 fax</small><br>
                <small>sales.office@finelumber.com</small><br>
                <small>www.finelumber.com</small><br>
            </div>
        </div>
        <div class="info-block">
            <h3>PROFILE NAME</h3>
            <h2>{{$data->profile_name}}</h2>
            <ul class="tiknesWidth">
                <li style="margin-left: -40px;">
                    <h3>THICKNESS</h3>
                    <span style="margin-left: -40px;">{{(($data-
                    >dimensions_first > 0) ? $data->dimensions_first : '' ) 
                    . (($data->dimensions_first == 0 || $data-
                    >dimensions_sub_first == 0) ? '' : '-') . (($data-
                    >dimensions_sub_first > 0 ) ? $data-
                      >dimensions_sub_first : '')}}</span>
                </li>
                <li style="margin-left: 50px;">
                    <h3>WIDTH</h3>
                    <span>{{(($data->dimensions_second > 0) ? $data-
                    >dimensions_second : '') .(($data->dimensions_second == 
                    0 || $data->dimensions_sub_second == 0) ? '' : '-'). 
                    (($data->dimensions_sub_second > 0) ? $data-
                    >dimensions_sub_second : '')}}</span>
                </li>
            </ul>
            <h3>SPECIES IN STOCK</h3>
            <span>
                    @if ($data->stock)
                    @foreach($data->stock as $key => $stock)
                        @if (count($data->stock) == $key + 1)
                            {{$stock->name}}
                        @else
                            {{$stock->name.','}}
                        @endif
                    @endforeach
                @endif
            </span>
            <h3>CATEGORY</h3>
            <span>{{$data->category->name}}</span>
            <h3>Fine Lumber ID</h3>
            <span>{{$data->lumber_id}}</span>
            <h3>Fine Lumber Location</h3>
            <span>{{$data->lumber_location}}</span>
        </div>

    </div>
</body>

0 个答案:

没有答案