3
votes

I want to generate PDF file from a view in laravel5. I found https://github.com/barryvdh/laravel-dompdf and added to my project via composer.

but it is not working,

 $pdf = PDF::loadView('invoice', array());
 return $pdf->download('invoice.pdf');

Getting error is

ErrorException in InvoiceController.php line 34: Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically, assuming $this from incompatible context

Is there any other package for laravel5?

3
You need to use the facade, you can simply add a backslash like this \PDF::loadView()user3718908

3 Answers

1
votes

try:

$pdf = App::make('dompdf');
$pdf->loadView('invoice', array());
return $pdf->download('invoice.pdf');

Regards

0
votes

I worked with 2 method for HTML to PDF

1.MPDF
2.Snappy PDF developed using WKHTML to PDF

Follow those 2 url you can use them using composer require.It will definitely help

For SNAPPY:http://www.kingpabel.com/php-html-to-pdf-snappy/
For MPDF:http://www.kingpabel.com/mpdf-for-php-to-pdf/

0
votes
 public function export(PDF $pdf, Student $students) {
   $students= $students->all();
    //  $brand = Brands::all();//todo: sort folder and conrtoller
    $results=[];
    $pdf = $pdf->loadView('dashboard.strs.manage.reports.examreports.exampdfreport',compact('students'));
    return $pdf->stream();
}

This method loads the pdf dialog box allows you to save your file as you would prefer.