简体   繁体   English

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

[英]How to display Hindi font in DOMPDF using laravel?

This is the pdf blade file in larval. 这是larval中的pdf刀片文件。 It gives ? 它给 ? mark in pdf file. 在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>

The resulting PDF looks like this: 生成的PDF如下所示:

PDF输出示例

I see two problems: 我看到两个问题:

  1. You don't specify the devanagari subset when referencing the font. 引用字体时,不指定梵文子集。

The default font subset served by Google Fonts usually includes only Latin characters (iso-8859-1). Google字体提供的默认字体子集通常仅包含拉丁字符(iso-8859-1)。 This is for performance reasons. 这是出于性能原因。 To include the devanagari characters your font reference should be as follows: 要包含梵文字符,您的字体引用应如下所示:

<link href="https://fonts.googleapis.com/css?family=Noto+Sans&subset=devanagari" rel="stylesheet">
  1. You don't actually specify that you want to use the font. 您实际上并未指定要使用该字体。

The only style you have attached to the page is the following: 您附加到页面的唯一样式如下:

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

but this CSS you use to reference a font file not to tell the HTML renderer (dompdf) to use the font. 但是这个CSS用来引用字体文件而不是告诉HTML渲染器(dompdf)使用该字体。 You can remove that code. 您可以删除该代码。 To actually use the font in the document you can use the following style: 要在文档中实际使用该字体,您可以使用以下样式:

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

Some relevant resources: 一些相关资源:


Finally a note: I would recommend using the latest version of dompdf (currently 0.7.0) since font support improves with each release. 最后一点说明:我建议使用最新版本的dompdf(目前为0.7.0),因为每个版本的字体支持都会有所改进。 There are some known, unresolved issues with the current release that could affect how your text renders ( see issue #655 ). 当前版本中存在一些已知的未解决的问题,这些问题可能会影响文本的呈现方式( 请参阅问题#655 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM