【问题标题】:Laravel PDF bangla font not supportedLaravel PDF 孟加拉字体不支持
【发布时间】:2021-01-02 18:07:31
【问题描述】:

在我的 Laravel 6 网络应用程序中,bangla 工作正常。但是当我打印报告时,孟加拉字体不显示。见截图。

我的打印页面代码是:

<!DOCTYPE html>
<html lang="en"> 
<head>
  <meta charset="utf-8">
  <title>Daily Purchase Reprt pdf</title>
  <style>
       {
        font-family: 'Baloo Da 2', cursive;
      }
  </style>
</head>
<body>
    <table width="100%">
      <tbody>
        <tr>
          <td width="60%" style="text-align: center; font-size: 25px;"> <strong style="text-align: center;">Kopotakkho Enterprise</strong> </td> <br> 
        </tr>
      </tbody>
    </table>
    <table width="100%">
      <tbody>
        <tr>
          <td width="30%" style="float: left;"> </td>
          <td width="40%" style="text-align: justify;"> 123, Kakrail Road , Moubon Super Market(2nd Floor), Shantinagar, Dhaka - 1217</td>
          <td width="30%" style="float: right;"></td> 
        </tr>
      </tbody>
    </table>
    <h3 style="text-align: center; text-decoration: underline;">Daily Purchase Report ({{ date('d-m-Y', strtotime($start_date)) }} - {{ date('d-m-Y', strtotime($end_date)) }})</h3>

    <table width="100%">
      <tbody>


      </tbody>

    </table>
<br>
                <table width="100%" border="1">
                  <thead>
                  <tr>
                    <th width="5%">S/N</th>
                    <th width="10%">Prch. No</th>
                    <th width="10%">Date</th>
                    <th width="5%">Category</th>
                    <th width="10%">Product</th>
                    <th width="10%">Qty</th>
                    <th width="15%">Unit Price</th>
                    <th width="15%">Total Price</th>
                  </tr>
                  </thead>
                  <tbody>
                    @php 
                      $sum_total = '0';
                    @endphp
                    @foreach($allData as $key => $purchase)
                  <tr>
                    <td style="text-align:center;">{{ $key+1 }}</td>
                    <td style="text-align:center;">{{ $purchase->purchase_no }}</td>
                    <td style="text-align:center;">{{ date('d-m-Y', strtotime($purchase->date)) }}</td>
                    <td style="text-align:center;">{{ $purchase['category']['cat_name'] }}</td>
                    <td style="text-align:center;">{{ $purchase['product']['product_name'] }}</td>               
                    <td style="text-align:center;">
                      {{ $purchase->buying_qty }}
                      {{ $purchase['product']['unit']['unit_name'] }}
                    </td>
                    <td style="text-align:center;">{{ $purchase->unit_price }}</td>
                    <td style="text-align:center;">{{ $purchase->buying_price }}</td>
                    @php 
                    $sum_total += $purchase->buying_price;
                  @endphp
                  </tr>


                  @endforeach
                  <tr>
                    <td colspan="7" style="text-align:right;"> Grand Total &ensp;</td>
                    <td style="text-align:center;">{{$sum_total}}</td>
                  </tr>                  
                </table>

                @php 
                  $date = new DateTime('now', new DateTimezone('Asia/Dhaka'));
                @endphp

                <i>Printing time : {{ $date->format('F j, Y, g:i a')}}</i>
<hr>
<br><br>
                <table>
                  <tr>
                    <td width="30%" style="float:left;">Customer Signature</td>
                    <td width="40%"></td>
                    <td width="30%" style="float:right; padding-left: 70px;"><span style="    padding-left: 50px; text-align: center;">Author Signature</span></td>
                  </tr>
                </table>
</body>
</html>

我使用了 "niklasravnsborg/laravel-pdf": "^4.0" 包进行​​打印。

在我的 pdf.php 文件中代码是:

<?php

return [
    'mode'                  => 'utf-8',
    'format'                => 'A4',
    'author'                => '',
    'subject'               => '',
    'keywords'              => '',
    'creator'               => 'Laravel Pdf',
    'display_mode'          => 'fullpage',
    'tempDir'               => base_path('../temp/')
];


return [
    // ...
    'font_path' => base_path('public/admin/Baloo_Da_2/'),
    'font_data' => [
        'BalooDa2' => [
            'R'  => 'BalooDa2-Regular.ttf',    // regular font
            'B'  => 'BalooDa2-Bold.ttf',       // optional: bold font
            'useOTL' => 0xFF,    // required for complicated langs like Persian, Arabic and Chinese
            'useKashida' => 75,  // required for complicated langs like Persian, Arabic and Chinese
        ]
        // ...add as many as you want.
    ]
    // ...
];

但孟加拉语没有显示。请帮忙。谢谢

【问题讨论】:

  • 在编写任何 html 之前尝试$mpdf-&gt;autoScriptToLang = true
  • 还有$mpdf-&gt;baseScript = \Mpdf\Ucdn::SCRIPT_BENGALI
  • 也试试这个:$mpdf-&gt;default_font = 'BalooDa2';

标签: laravel pdf


【解决方案1】:

您需要在项目中嵌入孟加拉字体。在 config/pdf.php 文件中请添加孟加拉字体。遵循此程序。

'font_path'             => base_path('resources/fonts/'),
'font_data' => [
            'solaimanlipi' => [
                'R'  => 'SolaimanLipi.ttf',    // regular font
                'B'  => 'SolaimanLipi.ttf',       // optional: bold font
                'I'  => 'SolaimanLipi.ttf',     // optional: italic font
                'BI' => 'SolaimanLipi.ttf', // optional: bold-italic font
                'useOTL' => 0xFF,
                'useKashida' => 75,
            ]
            ]

并下载“SolaimanLipi”字体并将其放置到您的资源/字体文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 2017-09-06
    • 1970-01-01
    • 2016-08-01
    • 2016-12-12
    • 1970-01-01
    • 2017-06-27
    相关资源
    最近更新 更多