0

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>

1 Answer 1

0

I already had a problem like this with wkhtmltopdf. My problem was related to wkhtmltopdf.exe which was not in the right place. The link in my code does not match the location of wkhtmltopdf.exe

Make sure that your wkhtmltopdf.exe is in the "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" and not else where. If it is not in the right place move the whole folder.

I hope this will help you

Sign up to request clarification or add additional context in comments.

1 Comment

the binary path is checked and its correctly placed still issue persist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.