0

Please, give me answer, how i can add external font in dompdf load view :) This is my structure `

Fonts folder exists in storage/fonts/ and fonts are exists in vendor/dompdf/dompdf/lib/fonts/ And this is my code `

This is my controller

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();
}

View ` text in tag is my css code for pdf view and text in tag is my html tag

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

Levon Babayan
  • 266
  • 2
  • 18
  • Possible duplicate of [Dompdf and set different font-family](https://stackoverflow.com/questions/24412203/dompdf-and-set-different-font-family) – BrianS Aug 07 '17 at 22:48
  • The process for adding fonts to Dompdf isn't generally specific to the installation. So long as you Laravel configuration is ok (and it looks like it is) you should be able to use the recommended method of referencing the font in your CSS. – BrianS Aug 07 '17 at 22:50
  • Here's something more specific to Laravel: https://stackoverflow.com/questions/43636379/laravel-dompdf-add-custom-font – BrianS Aug 07 '17 at 22:51

0 Answers0