@deron
You can convert a Blade file into a PDF and an image in Laravel using the following steps:
1 2 |
composer require barryvdh/laravel-dompdf composer require intervention/image |
1 2 3 4 5 6 7 8 9 |
Route::get('pdf', function () {
$data = [
'title' => 'Sample PDF',
'content' => 'This is the content of the PDF file'
];
$pdf = PDF::loadView('pdf.blade', $data);
return $pdf->download('pdf_file.pdf');
});
|
1 2 3 4 5 6 7 8 9 |
Route::get('image', function () {
$data = [
'title' => 'Sample Image',
'content' => 'This is the content of the image'
];
$img = Image::make('pdf.blade')->encode('jpg');
return $img->response();
});
|
Now you can access the /pdf and /image routes in your browser to download the converted PDF and image files respectively.