I am trying to generate a PDF report in my application using the barryvdh/laravel-dompdf
package, but I'm receiving an error:
Class 'PDF' not found
I have followed steps from previous answers to similar questions, but they don't seem to help me.
I added the following lines in my composer.json file:
"barryvdh/laravel-dompdf": "^0.8.0",
"dompdf/dompdf": "0.8.0 as 0.6.2"
Then, I ran composer update
. Afterwards, I included the following lines in my config/app.php
:
Barryvdh\DomPDF\ServiceProvider::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
And finally, I ran the following commands in my terminal:
php artisan cache:clear
php artisan config:cache
Controller
Use PDF;
$pdf = PDF::loadView('app.feestdreportprint',compact('datas','rdata','stdinfo','institute'));
return $pdf->stream('student-Payments.pdf');
But I am still getting the same error. What can I do to solve this issue? My laravel version is 5.4
.
please check if you put
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
as alias en app.php
I'm using other library maybe you can use it too.
Composer require:
"barryvdh/laravel-dompdf": "^0.8.1",
"barryvdh/laravel-snappy": "^0.4.0",
Provider: Barryvdh\Snappy\ServiceProvider::class,
Alias: 'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
In the controller:
use Barryvdh\DomPDF\PDF;
Eg.
$pdf = App::make('snappy.pdf.wrapper');
$view = View::make('view::quote.pdf',['data' => $data]);
$pdf->loadHtml($view)->save($file);
first you have to put this lines in config/app.php
.
'providers' => [Barryvdh\DomPDF\ServiceProvider::class],
and
'aliases' => ['PDF' => Barryvdh\DomPDF\Facade::class]
and then you have to use this in your function its totally work for me example
$pdf = PDF::loadView('admin/order_pdf',compact('order_item','order','total_qty','total_ltr','total_weight'));
$pdf->save(storage_path().'_filename.pdf');
return $pdf->download('customers.pdf');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.