我在 laravel 元素中使用 dompdf 包创建了我的 pdf。但是当我想呈现其他语言(孟加拉语)而不是英语时
????????????????????????????
显示。
<body style="font-family: 'AdorshoLipi', Arial, sans-serif !important;">
<div style="border-style: solid; border-width: 2px; margin: 50px; padding: 10px;">
<div align="center">
<h2>
Anti-corruption commission hotline-106
</h2>
</div>
<div>
<p> Reference No : {{ $complain->call_ref_id }}</p>
{{-- <br> --}}
<p> Date : {{ $complain->created_at }}</p>
<p> Name : {{ $complain->name }}</p>
<p> Address : {{ $complain->address }}</p>
<p> Phone Number : {{ $complain->phone_number }}</p>
<p> Against : {{ $complain->against }}</p>
<p> Sector : {{ $complain->department }}</p>
<p style="font-family: 'AdorshoLipi', Arial, sans-serif !important;"> Type : {{ $complain->type }}</p>
<p> Complain Description : {{ $complain->complain_description }}</p>
<p> Amount : {{ $complain->amount }}</p>
<p> Status : {{ $complain->status }}</p>
</div>
<div style=" margin-left: 450px; width: 100px; ">
<hr>
<label>Signature</label>
</div>
<div class="panel-primary">
</div>
</div>
</body>
最佳答案
您可以在 laravel 中添加对 TrueType 字体的支持 Dompdf package .只需按照以下步骤从命令行将 TrueType 字体加载到 dompdf。
有两种基本方法可以通过此包使用 TrueType 字体系列:
1) 使用load_font.php脚本
2) 使用@font-face css 规则在运行时加载字体
1) 使用 load_font.php 脚本
load_font.php 是一个使用命令行运行的脚本,因此您需要从命令行运行命令。您可以轻松地从 Dompdf utils
获取此脚本
添加此实用程序后,在命令行界面中运行以下命令以从 dompdf 安装目录安装字体。
php load_font.php font_family /pathto/fontfile.ttf
注意:dompdf 目前仅支持 TrueType 字体。因此,在查找字体时,请确保它采用 TrueType 格式。
2) 使用 @font-face
在运行时加载字体的 css 规则
您只需将以下样式脚本添加到您的页面中,即可使用 TrueType 字体。
@font-face {
font-family: 'font_family';
font-style: normal;
font-weight: normal;
src: url(http://example.com/fonts/fontfile.ttf) format('truetype');
}
加载上述字体后,您可以像这样使用它:<div style="font-family: font_family, sans-serif;">yourtextinotherlanguage</div>
确保您的文档指定使用 UTF-8,如 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
.
可以找到更多信息 here也是
关于php - Dompdf 封装 laravel 中其他语言的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45714545/