Laravel:尝试获取 PDF 时出现 DOMPDF 错误
Laravel: DOMPDF error when trying to get PDF
我一直在尝试使用 DOMPDF 获取视图的 PDF,其中 table 包含从数据库 table 填充的所有成分。
我在控制器中创建了一个函数:
public function createPDF() {
// retreive all records from db
$data = Ingredients::all();
// share data to view
view()->share('ingredients', $data);
$pdf = PDF::loadView('printableingredientslist', $data);
// download PDF file with download method
return $pdf->download('printableingredientslist.pdf');
}
而web.php中的路由定义为:
Route::get('/printpreviewingredients/pdf', [MealPlanDisplayController::class, 'createPDF']);
但是,我不断收到此错误:
fopen(D:\mealplan\storage\fonts//nunito_normal_46b9b3b48cc3ddbae60da82f1c1c5d29.ufm):
failed to open stream: No such file or directory
它一定与“printableingredientslist
”有关,因为当我将其替换为带有简单文本的 plain view page
时,它就起作用了。然而,我正在努力查看路径问题,因为 printableingredientslist.blade.php
就在 views 文件夹下。问题是什么?我正在使用 tailwind.css
,会不会有问题?
setOptions
使用默认方法的方法 font.For 示例如下
public function pdf()
{
$pdf = \PDF::loadView('contact')->setOptions(['defaultFont' => 'sans-serif']);
return $pdf->download('invoice.pdf');
}
或
在storage
目录
中创建目录fonts
参考:https://github.com/barryvdh/laravel-dompdf/issues/724
我一直在尝试使用 DOMPDF 获取视图的 PDF,其中 table 包含从数据库 table 填充的所有成分。
我在控制器中创建了一个函数:
public function createPDF() {
// retreive all records from db
$data = Ingredients::all();
// share data to view
view()->share('ingredients', $data);
$pdf = PDF::loadView('printableingredientslist', $data);
// download PDF file with download method
return $pdf->download('printableingredientslist.pdf');
}
而web.php中的路由定义为:
Route::get('/printpreviewingredients/pdf', [MealPlanDisplayController::class, 'createPDF']);
但是,我不断收到此错误:
fopen(D:\mealplan\storage\fonts//nunito_normal_46b9b3b48cc3ddbae60da82f1c1c5d29.ufm): failed to open stream: No such file or directory
它一定与“printableingredientslist
”有关,因为当我将其替换为带有简单文本的 plain view page
时,它就起作用了。然而,我正在努力查看路径问题,因为 printableingredientslist.blade.php
就在 views 文件夹下。问题是什么?我正在使用 tailwind.css
,会不会有问题?
setOptions
使用默认方法的方法 font.For 示例如下
public function pdf()
{
$pdf = \PDF::loadView('contact')->setOptions(['defaultFont' => 'sans-serif']);
return $pdf->download('invoice.pdf');
}
或
在storage
目录
fonts
参考:https://github.com/barryvdh/laravel-dompdf/issues/724