如何使用laravel在DOMPDF中显示印地语字体?

时间:2016-09-09 09:52:28

标签: php html laravel-5 dompdf

这是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如下所示:

Sample PDF Output

1 个答案:

答案 0 :(得分:0)

我看到两个问题:

  1. 在引用字体时,您没有指定梵文字节子集。
  2. Google字体提供的默认字体子集通常只包含拉丁字符(iso-8859-1)。这是出于性能原因。要包含梵文字符,您的字体引用应如下所示:

    <link href="https://fonts.googleapis.com/css?family=Noto+Sans&subset=devanagari" rel="stylesheet">
    
    1. 您实际上并未指定要使用该字体。
    2. 您附加到页面的唯一样式如下:

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