Install this:
then install this two,
$ composer require h4cc/wkhtmltopdf-i386 0.12.x $ composer require h4cc/wkhtmltoimage-i386 0.12.x
Then, composer require barryvdh/laravel-snappyThen,php artisan vendor:publish --provider="Barryvdh\Snappy\ServiceProvider"
And Now,
copy the wkhtmltopdf.exe and wkhtmltoimage.exe files to the above h4cc folder which
is present inside vendor folder of laravel. and set the path to
snappy.php file-> see the snappy.php file which is given below:
snappy.php file-> see the snappy.php file which is given below:
[NOTE: see the code which i've commented out. You can run & check every line of code]
Route::get('/', function () {
$data = [
[
'name'=>'Audi',
'logo'=>'audi.jpg'
],
[
'name'=>'Rolex',
'logo'=>'audi.jpg'
],
];
$pdf = PDF::loadView('pdf.tutorial',['cars'=>$data]);
// $html = "<h1>Hello World</h1>";
// $pdf = PDF::loadHtml($html);
$pdf->setOrientation('landscape');
// $pdf->setOption('header-left','[page]');
// $pdf->setOption('header-right','[date]');//[page] or [date]
// $pdf->setOptions([
// // 'header-left'=>'[page]',
// // 'header-right'=>'[date]',
// // 'footer-right'=>'Bitfumes',
// // you can set this options inside snappy.php files option
// ]);
//$pdf->setOption('footer-html',view('pdf.footer'));
// return $pdf->download('hello.pdf');
return $pdf->stream('hello.pdf');
});
Snappy.php file looks like this:
'pdf' => [
'enabled' => true,
'binary' => env('WKHTML_PDF_BINARY', base_path('vendor/h4cc/wkhtmltopdf')),
'timeout' => false,
'options' => [
'header-left'=>'[page]',
'header-right'=>'[date]',
'footer-right'=>'Bitfumes',
],
'env' => [],
],
'image' => [
'enabled' => true,
'binary' => env('WKHTML_IMG_BINARY',base_path('vendor/h4cc/wkhtmltoimage')),
'timeout' => false,
'options' => [],
'env' => [],
],
tutorials.blade.php blade is present inside pdf folder
& tutorials.blade.php file looks like this:
& tutorials.blade.php file looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Tutorial PDF</title>
<style>
th,td{
border: 1px solid black;
border-collapse: collapse;
}
th,td{
padding: 15px;
text-align: left;
}
table{
width: 100%;
background-color: #f1f1c1;
}
</style>
</head>
<body>
<table class="table table-light">
<thead>
<tr>
<th>S. No</th>
<th>Name</th>
<th>Image</th>
</tr>
</thead>
<tbody>
@foreach($cars as $car)
<tr>
<td>1. </td>
<td>{{$car['name']}}</td>
<td>
<img src="{{public_path('/'.$car['logo'])}}" width="150" alt="">
</td>
</tr>
@endforeach
</tbody>
</table>
</body>
</html>
HOPE THIS WILL HELP SOMEBODY IN THIS WORLD! HAPPY CODING. (PRITAM DATTA)
Comments
Post a Comment