How to convert html to PDF in laravel ?

Solution :

Step1 :  add following to your composer.json file

“barryvdh/laravel-dompdf”: “0.6.*”,

step2: update your composer using command.

composer update or php composer.phar update

step3: After update your composer. open app.php

path : config/app.php

Step4 : Add following line in  ‘providers’

Barryvdh\DomPDF\ServiceProvider::class

step5: Add following line in aliases

‘PDF’ => Barryvdh\DomPDF\Facade::class

step6 : suppose you want to use in your UserController then add following line above your class name.

use PDF;

step6: Suppose you want to print all user

Here is example

$user =  User::all(); // from this you will get list of user and you ll render on view

return view(‘user.index’, compact(‘resetUrl’,’user’));

similarly, if you want to generate PDF then you do following

 

$pdf = PDF::loadView(‘user.index’, compact(‘user’));

//in view folder there is user folder inside that you have index file where you list all user

/—Below code generate your html view to PDF/

return ($pdf->download(‘user.pdf’));

// user.pdf is named for example , you can write as per your need.

Add Comment

Required fields are marked *. Your email address will not be published.