I’ve been trying to get the PDF of a view using DOMPDF with a table full of ingredients populated from a database table.
I created a function in my Controller:
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'); }
And the route in web.php is defined as:
Route::get('/printpreviewingredients/pdf', [MealPlanDisplayController::class, 'createPDF']);
However, I keep getting this error:
fopen(D:mealplanstoragefonts//nunito_normal_46b9b3b48cc3ddbae60da82f1c1c5d29.ufm): failed to open stream: No such file or directory
It must be something to do with the ‘printableingredientslist
‘ as when I replaced it with a plain view page
with simple text that worked. I am struggling to see how there’s a path issue however, as printableingredientslist.blade.php
is simply under the views folder. What can the issue be? I am using tailwind.css
, could that be a problem?
Advertisement
Answer
setOptions
method to use default font.For example like below
public function pdf() { $pdf = PDF::loadView('contact')->setOptions(['defaultFont' => 'sans-serif']); return $pdf->download('invoice.pdf'); }
or
Create the directory fonts
in storage
directory
Ref: https://github.com/barryvdh/laravel-dompdf/issues/724