孟加拉 unicode 字体未在 mpdf 中显示

问题描述 投票:0回答:2

我正在使用 mpdf 生成 pdf。虽然该文档包含孟加拉 unicode 字体,但它在 pdf 文档中不可见。

我已在 config/pdf.php 中正确包含字体

'bangla' => [
            '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, 
        ]

渲染孟加拉文本的CSS样式

.textLayer > div {
color: transparent;
white-space: pre;
cursor: text;
transform-origin: 0% 0%;
}

当我更改颜色时,它会显示重复的文本。

Output

laravel fonts mpdf
2个回答
4
投票

您的配置正确。请确保您的字体文件位于 ttfonts 文件夹中。然后在你的html文件中你这样写

    html, body, div {
      font-family: bangla;
    }

我使用了字体系列名称bangla,因为你在这里配置了它,

'bangla' => [
        'R'  => 'SolaimanLipi.ttf', // regular font
        'B'  => 'SolaimanLipi.ttf',
        ..........
        'useOTL' => 0xFF,
        'useKashida' => 75]

现在你应该这样调用 mPDF,

$mpdf = new \Mpdf\Mpdf([
            'default_font' => 'bangla',
            'mode' => 'utf-8'
        ]);

现在在你的情况下,对于像这样的CSS调用,

.textLayer > div {
   font-family: bangla;
   color: transparent;
   white-space: pre;
   cursor: text;
   transform-origin: 0% 0%;
 }

应该可以。


0
投票

有时,如果您更改供应商文件夹,会产生很多问题。特别是如果您想更新插件。所以我的解决方案是,

添加到config/pdf.php

return [
'custom_font_dir'  => base_path('resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
    'solaimanlipi' => [ // must be lowercase and snake_case
        'R'  => 'SolaimanLipi-Regular.ttf',    // regular font
        'B'  => 'SolaimanLipi-Bold.ttf',       // optional: bold font
        'I'  => 'SolaimanLipi-Italic.ttf',     // optional: italic font
        'BI' => 'SolaimanLipi-Bold-Italic.ttf' // optional: bold-italic font
    ]
  // ...add as many as you want.
]];

现在在视图文件上添加CSS

body {font-family: 'solaimanlipi', sans-serif;}
© www.soinside.com 2019 - 2024. All rights reserved.