【发布时间】:2019-05-16 11:05:36
【问题描述】:
我尝试在 Laravel Dompdf 中导入我的自定义字体 VAGRooned_BT.ttf。我已将 config/dompdf.php 中的目录以及 font_cache 更改为 public/fonts/。但我无法在我的 PDF 中显示字体。
互联网上提供的几种解决方案对我没有帮助。我找不到问题,分别是如何导入我的字体。我尝试了不同的字体,比如 Lato 或 Roboto,但总是一样。
config/dompdf.php 的变化
"font_dir" => storage_path('public/fonts/'),
"font_cache" => storage_path('public/fonts/'),
控制器功能:
public function deliveryDetailsPDF($delivery_id){
$header = Delivery::where('id',$delivery_id)->first();
$details = Delivery::getDeliveryDetails($delivery_id);
$pdf = \PDF::setOptions([
'isHtml5ParserEnabled'=> true,
'isRemoteEnabled' => true,
])
->loadView('delivery.pdf',compact('header','details'))
->stream();
return $pdf;
}
Blade文件delivery/pdf.blade.php头部中的样式块:
<style>
@font-face{
font-family: VAGBlack;
src:url('/fonts/VAGRounded_BT.ttf');
/* src:url({{ storage_path('fonts\VAGRounded_BT.ttf') }}) format("truetype"); */
}
h1, h2 {
font-family:VAGBlack;
font-size: 14pt;
color:black;
}
</style>
在生成的 PDF 中仍然使用 Arial。 我怎样才能达到我的目标?
提前谢谢你。
【问题讨论】:
标签: dompdf custom-font laravel-5.8