If you are working on big project like shop management or any kind of ERP system ,You have to generate PDF for that.So if you use laravel for back end ,it is very easy to use.So follow the step one by one.
Step 1
In this post we are using laravel-dompdf package for createing pdf file.So first of all we have to download laravel-dompdf plugin for generate pdf file from view blade file. So start the cmd and go to your project folder path.Run the following command.
composer require barryvdh/laravel-dompdf
Next open the config/app.php file and add service provider and aliases in the provider and aliases array.
'providers' => [ .... Barryvdh\DomPDF\ServiceProvider::class, ], 'aliases' => [ .... 'PDF' => Barryvdh\DomPDF\Facade::class, ],
Step 2
Now create a view file with name pdf.blade.php.You can use another name as your choice.Add the following code in your view file.
<table style="width:100%"> <tr> <th>Product name</th> <th>Product Price</th> <th>Product Description</th> </tr> <tr> <td>{{ $items['product_name'] }}</td> <td>{{ $item['product_price'] }}</td> <td>{{ $item['product_description'] }}</td> </tr> </table>
You can add custom css as you want to make the pdf colorful.
Step 3
Now in your controller call the view file and add the following code.
$items=array('product_name'=>$product_name,'product_price'= >$product_price,'product_description'=>$product_description); view()->share('items',$items); $pdf = PDF::loadView('pdf_folder.pdf'); $filename=time().'.pdf'; //PDF will be storage in storage/app/public/pdf_folder folder Storage::put('public/pdf/'.$ filename, $pdf->output());
That’s all.Now you can run and check.