Laravel 5 - dompdf doesn't work - Any fix there? Hello Laravel-Community,
i use Laravel 5 for a little project and want to create a pdf out of a webpage. Therefore i used the laravel-dompdf package from github "https://github.com/barryvdh/laravel-dompdf". I tried out many things but none of the codes i could find on the internet have worked. Maybe someone can guide me to a tutorial or help me to integrate this functionality.
Greetings and thanks in advance,
Marcel
@lockeyo , in order for anyone on the forum to help you, you need to be more specific. What have you tried yet, what is 'not working', do you get any errors etc.
Show us what you tried and what the result is and people can try and help you :)
I easily followed the instructions listed here: https://github.com/barryvdh/laravel-dompdf
Then I created this method in one of my controllers and set a route to it:
public function generate()
{
$pdf = PDF::loadHTML('<h1>Test</h1>');
return $pdf->stream();
}
But when opening this site in the browser, it's empty!
Try to save it to a file, to make sure it's not a problem with your browser or something.
Okay strangely enough it's working when I don't call an controller action, but trigger it in routes.php directly
get('/pdf', function(){
$pdf = PDF::loadHTML('<h1>Test</h1>');
return $pdf->stream();
});
Any suggestions what the reason is?
Does it work when you use \PDF:: ?
Might be a namespace problem, although I expect that that should have resulted in an exception
Wonderful, it works now using "\PDF::"
Thanks for your help! :)
No problem, just remember that in L5, namespaces are used and you need to escape facades in order to use them :)
If you want you can mark the answer :)
To Use Dom PDF via View Try this:
Installing the package :
Require this package in your composer.json - "barryvdh/laravel-dompdf": "0.5.*"
composer update
add the ServiceProvider to the providers array in config/app.php - 'Barryvdh\DomPDF\ServiceProvider',
Add this to your facades for shortcut: - 'PDF' => 'Barryvdh\DomPDF\Facade',
composer dump-autoload;
$data = [];
$pdf = \App::make('dompdf');
$pdf->loadView('pdfs.qpdf', $data);
return $pdf->download('quotation.pdf');
Or
use App;
$data = [];
$pdf = App::make('dompdf');
$pdf->loadView('pdfs.qpdf', $data);
return $pdf->download('quotation.pdf');
I've try above, but I've got this error:
2016/03/28 16:00:50 [error] 780#780: *3247 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class view does not exist' in /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Container/Container.php:741
Stack trace:
#0 /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(741): ReflectionClass->__construct('view')
#1 /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(631): Illuminate\Container\Container->build('view', Array)
#2 /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make('view', Array)
#3 /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(1163): Illuminate\Foundation\Application->make('Illuminate\Cont...')
#4 /home/vagrant/web/api.com/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php(144): Illuminate\Conta...
$pdf->loadView('pdfs.qpdf', $data);
The error tells that you dont have html view page(pdfs.qpdf) in your laravel application.try to add a html view page then error rectifies.
The updated version works with this code.
Installing the package :
Require this package in your composer.json -"barryvdh/laravel-dompdf": "0.6.*"
composer update
3.composer update
4.add the ServiceProvider to the providers array in config/app.php - Barryvdh\DomPDF\ServiceProvider::class,
5.Add this to your facades for shortcut: -
'PDF' => Barryvdh\DomPDF\Facade::class,
$pdf = App::make('dompdf.wrapper');
$data = []; // you can push your data in this to the pdf.
$pdf = PDF::loadView('PATHOFTHEVIEW', $data);
return $pdf->download('KEEPTHENAMEYOUWANT.pdf');
I have the same problem but \PDF did not solve the problem . any one can help ?
Please sign in or create an account to participate in this conversation.