Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lockeyo's avatar

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

0 likes
13 replies
MThomas's avatar

@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 :)

lockeyo's avatar

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!

RachidLaasri's avatar

Try to save it to a file, to make sure it's not a problem with your browser or something.

lockeyo's avatar

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?

MThomas's avatar
MThomas
Best Answer
Level 35

Does it work when you use \PDF:: ?

Might be a namespace problem, although I expect that that should have resulted in an exception

2 likes
lockeyo's avatar

Wonderful, it works now using "\PDF::"

Thanks for your help! :)

MThomas's avatar

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 :)

1 like
deepesh's avatar

To Use Dom PDF via View Try this:


Installing the package :

  1. Require this package in your composer.json - "barryvdh/laravel-dompdf": "0.5.*"
  2. composer update
  3. add the ServiceProvider to the providers array in config/app.php - 'Barryvdh\DomPDF\ServiceProvider',
  4. Add this to your facades for shortcut: - 'PDF' => 'Barryvdh\DomPDF\Facade',
  5. 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');


1 like
osaev's avatar

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...

veerendra's avatar

$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.

deepesh's avatar

The updated version works with this code.

Installing the package :

  1. Require this package in your composer.json -"barryvdh/laravel-dompdf": "0.6.*"
  2. 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: -

  1. 'PDF' => Barryvdh\DomPDF\Facade::class,

  2. $pdf = App::make('dompdf.wrapper');

$data = []; // you can push your data in this to the pdf.

  1. $pdf = PDF::loadView('PATHOFTHEVIEW', $data); return $pdf->download('KEEPTHENAMEYOUWANT.pdf');
MWDeveloper's avatar

I have the same problem but \PDF did not solve the problem . any one can help ?

Please or to participate in this conversation.