https://github.com/barryvdh/laravel-dompdf
or https://laravel-excel.com/
1
composer require barryvdh/laravel-dompdf
2
'providers' => [
....
Barryvdh\DomPDF\ServiceProvider::class,
],
3
'aliases' => [
....
'PDF' => Barryvdh\DomPDF\Facade::class,
]
4
Route::get('/customer/print-pdf', [ 'as' => 'customer.printpdf, 'uses' => 'CustomerController@printPDF']);
5
public function printPDF()
{
$userReport = array(
[
'name' => 'vishnu',
'email' => 'xyz@gmail.com',
'mobileNumber' => '9999999999',
],
[
'name' => 'vishnu',
'email' => 'xyz@gmail.com',
'mobileNumber' => '9999999999',
],
);
$pdf = PDF::loadView('pdf.pdf_view', ['userReports' => $userReport])->setPaper('a4', 'landscape');
return $pdf->download('Report-'. str_replace(" - ","",date('Y-M-D')).'.pdf');
}
6
<html>
<head>
<title>User Report</title>
</head>
<body>
<table border="1" id="customers" style="font-family:Trebuchet MS,Arial,Helvetica,sans-serif;width:100%;border-collapse:collapse; margin: 0 50px 0 0;">
<tbody><tr>
<th colspan="2" style="color:white;text-align:center;background-color: #03a9f3;padding:12px 8px;border:1px solid #DDDDDD;border-radius: 0; border-right: 0px;"><img height="50px" width="100px" src="https://assets.stickpng.com/images/580b57fcd9996e24bc43c51f.png" >
</th>
<th colspan="2" style="text-align:center;background-color: #03a9f3;padding:12px 8px;border:1px solid #DDDDDD;border-radius: 0; border-right: 0px;">
<h3><strong>User Report </strong></h3>
Date of Report : {{ date('Y-M-D') }}
</th>
</tr>
<tr>
<th style="width:10px; color: white; background-color: #03a9f3;padding: 12px 8px; text-align: left;"> No.</th>
<th style=" width:150px; color: white; background-color: #03a9f3;padding: 12px 8px; text-align: left; ">Name</th>
<th style="width:50px; color: white; background-color: #03a9f3;padding: 12px 8px; text-align: left;">Email</th>
<th style="width:150px; color: white; background-color: #03a9f3;padding: 12px 8px; text-align: left;">Mobile Number</th>
</tr>
@foreach($userReports as $key => $user)
@php
@endphp
<tr>
@php $key++; @endphp
<td style="padding:8px; width:10px;" >{{ $key ?? '' }}</td>
<td style="padding:8px; width:50px;" >{{ $user['name'] ?? '' }}</td>
<td style="padding:8px; width:50px;" >{{ $user['email'] ?? ''}}</td>
<td style="padding:8px; width:150px;" >{{ $user['mobileNumber'] ?? ''}}</td>
</tr>
@endforeach
</tbody></table>
</body>
</html>
Comments
Post a Comment