pdf file create in laravel
for createing pdf in laravel for purpose like invoice generation ... we can use ‘barryvdh/laravel-dompdf’
note: we using a fresh laravel application for this.
step 1: first install ‘barryvdh/laravel-dompdf’ using composer inside of laravel project.
composer require barryvdh/laravel-dompdf |
step 2: add these two lines inside arrays... inside config/app.php
'providers' => [ .... Barryvdh\DomPDF\ServiceProvider::class, ], 'aliases' => [ .... 'PDF' => Barryvdh\DomPDF\Facade::class, ] |
step 3: mention into routes.php
Route::get('pdfgenerate', [PDFController::class, 'generatePDF']); |
step 4: make a class like PDFController ... and paste the code.
use PDF;
public function generatePDF() { $data = [ 'title' => 'Welcome to microcodes.in', 'date' => date('m/d/Y') ]; $pdf = PDF::loadView('pdfPage', $data); return $pdf->download('itsolutionstuff.pdf'); } |
step 5: now i will make a blade file with name like ‘pdfPage’ like below...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>shimanta das page</title> </head> <body>
<br> <br> <br>
<p style="margin-left:auto;margin-right:auto;"> {{$title}}</p>
<br> <br>
<table> <tr> <th>NAME</th> <th>PHONE</th> </tr> <tr> <td>SHIMANTA DAS</td> <td>9330497982</td> </tr> <tr> <td>SANJOY DAS</td> <td>9932877636</td> </tr> </table> </body> </html> |