We all are trying to load a pdf with graph on it and send to email. However when trying to create a pdf file it shows error as failed with out error.
We are using library called as : "barryvdh/laravel-snappy": "^1.0"
Have installed library called as wkhtml2pdf however still the issue remain same.
Controller file :
public function download()
{
$render = view('graph')->render();
$pdf = new Pdf;
$pdf->addPage($render);
$pdf->setOptions([
'enable-javascript' => true,
'javascript-delay' => 5000,
'enable-smart-shrinking' => true,
'no-stop-slow-scripts' => true,
'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"'
]);
if(!$pdf->saveAs('D:/report.pdf')){
return $pdf->getError();
}
return response()->download('D:report.pdf');
}
Blade File:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://www.google.com/jsapi"></script>
<style>
.pie-chart {
width: 600px;
height: 400px;
margin: 0 auto;
}
.text-center{
text-align: center;
}
</style>
</head>
<body>
<h2 class="text-center">Generate PDF with Chart in Laravel</h2>
<div id="chartDiv" class="pie-chart"></div>
<div class="text-center">
<a href="{{ route('download') }}">Download PDF File</a>
<h2>ItSolutionStuff.com.com</h2>
</div>
<script type="text/javascript">
window.onload = function() {
google.load("visualization", "1.1", {
packages: ["corechart"],
callback: 'drawChart'
});
};
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Pizza');
data.addColumn('number', 'Populartiy');
data.addRows([
['Laravel', 33],
['Codeigniter', 26],
['Symfony', 22],
['CakePHP', 10],
['Slim', 9]
]);
var options = {
title: 'Popularity of Types of Framework',
sliceVisibilityThreshold: .2
};
var chart = new google.visualization.PieChart(document.getElementById('chartDiv'));
chart.draw(data, options);
}
</script>
</body>
</html>