【问题标题】:How to display Hindi font in DOMPDF using laravel?如何使用 laravel 在 DOMPDF 中显示印地语字体?
【发布时间】:2017-01-17 10:31:44
【问题描述】:

这是larval中的pdf刀片文件。它给 ?在pdf文件中标记。

@section('css')
    <meta name="viewport" content="width=device-width, initial-scale=1" >
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet">
    <style>
        @font-face {
            font-family: 'Noto Sans', sans-serif;
            font-style: normal;
            font-weight: 400;
        }
    </style>
@endsection
@section('js')
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
@endsection

       <div class="container">
            <h2>Leave Request Information</h2>
            <h3>Month - {{$month}} {{$year}}</h3>
            <br/>

            @if(isset($leavesRequest) && count($leavesRequest)>0)

                <table style="width:100%" border="1" cellspacing="0">
                    <thead>
                    <tr>
                        <th>S No.</th>
                        <th>अध्यापक कर्मचारी का नाम और पद</th>
                        <th>Name of school</th>
                        <th>Leave Type</th>
                        <th>Leave Status</th>
                        <th>Year</th>
                        <th>Month</th>
                        <th>Total Days</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php $i = 0; ?>
                    @foreach($leavesRequest as $status)
                        <?php ++$i; ?>
                        <tr>
                            <td style="text-align: center"><?php echo $i;?></td>
                            <td style="text-align: center"><?php echo $status->teacher->name;?></td>
                            <td style="text-align: center"><?php echo $status->school->name;?></td>
                            <td style="text-align: center">{{$status->leave_type}}</td>
                            <td style="text-align: center">{{$status->leave_status}}</td>
                            <td style="text-align: center">{{$status->leave_year}}</td>
                            <td style="text-align: center">{{$status->month_name}}</td>
                            <td style="text-align: center">{{$status->total_days}}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>

            @else

                No data found

            @endif

        </div>

生成的 PDF 如下所示:

【问题讨论】:

    标签: php html laravel-5 dompdf


    【解决方案1】:

    我看到两个问题:

    1. 您在引用字体时没有指定梵文子集。

    Google 字体提供的默认字体子集通常仅包含拉丁字符 (iso-8859-1)。这是出于性能原因。要包含梵文字符,您的字体参考应如下所示:

    <link href="https://fonts.googleapis.com/css?family=Noto+Sans&subset=devanagari" rel="stylesheet">
    
    1. 您实际上并未指定要使用该字体。

    您附加到页面的唯一样式如下:

    <style>
        @font-face {
            font-family: 'Noto Sans', sans-serif;
            font-style: normal;
            font-weight: 400;
        }
    </style>
    

    但是这个 CSS 用于引用字体文件而不是告诉 HTML 渲染器 (dompdf) 使用该字体。您可以删除该代码。要实际使用文档中的字体,您可以使用以下样式:

    <style>
      * { font-family: Noto Sans, sans-serif; }
    </style>
    

    一些相关资源:


    最后要注意:我建议使用最新版本的 dompdf(当前为 0.7.0),因为每个版本都改进了字体支持。当前版本存在一些已知的、未解决的问题,这些问题可能会影响您的文本呈现方式 (see issue #655)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-05
      • 2020-12-05
      相关资源
      最近更新 更多