.
We are going to use spatie browsershot
composer require spatie/browsershot
now you need to install npm dependency like pupeeteer
$ npm install puppeteer
make a file in resource like agreement.blade.php
in controller function
$template=view('Our Blade file name',['data'=>$data])->render(); //The Render function actually convert over blade file into string
now converting template veriable to pdf file using browsershot
Browsershot::html($template)->save(storage_path('/app/reports/example.pdf'));
//if we want to render styling too so we can use showbackground() method
Browsershot::html($template)
->showBackground()
->margins(4,4,4,4) //using short hand method top ,right , bottom, left
->landscape() //we can define orientation as well
->format('A4') //we can define document size
->save(storage_path('/app/reports/example.pdf'));