DomPDF API for PDF generation in PHP


I use the laragon software that already comes with laravel and composer integrated into the project, I ran the line:

Note: I haven't bothered with good practices yet, I want to make it work first

composer require barryvdh/laravel-dompdf

To install PDF generation api. Added the following lines in the app.php /config folder

In providers


in aliases

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

Imported in the class where the pdf generation method is

use PDF;

I've already used the code in several ways and none of them worked:

    $clientes = Cliente::all();
    $view = view('Pdf.PdfClientesReport2', compact('clientes'));
    $pdf = \App::make('dompdf.wrapper');      
    //Aqui ele conseguir ver pelo dd() que ele pega dados do pdf mas nao 
    consigo imprimir

This way also with a function within the generation method:

function geraTeste($clientes){

        $code = "<!DOCTYPE html>


        foreach ($clientes as $c){
            $code += "<tr>";
            $code += "<td>'.$c->name.'</td>";
            $code += "<td>'.$c->cpf_cnpj.'</td>";
            $code += "<td>'.$c->inscricao_est.'</td>";
            $code += "</tr>";

        $code += "</table>";
        $code += "</body>

        return $code;

    $clientes = Cliente::all();
    $pdf = \App::make('dompdf.wrapper');
    return $pdf->stream();

In this way too:

    $pdf = PDF::loadView('Pdf.PdfClientesReport2', compact('clientes'));
    return $pdf->download('invoice.pdf');

This one too:

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

I got it that way just now, but I wanted to be able to open it in the browser itself.

$pdf  =  \App::make('dompdf.wrapper');
    $view =  View::make('Pdf.PdfClientesReport2', compact('clientes'))->render();
    //return $pdf->stream('invoice');
    return $pdf->download('profile.pdf');

If anyone can help, I accept suggestions…


When you used the return $pdf->stream(); did not pass the name of the file to be mounted.

return $pdf->stream('profile.pdf');

So it should work.

Scroll to Top