Question:
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
Barryvdh\DomPDF\ServiceProvider::class,
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');
$pdf->loadHTML($view);
//Aqui ele conseguir ver pelo dd() que ele pega dados do pdf mas nao
consigo imprimir
//dd($pdf);
$pdf->download('clientes');
This way also with a function within the generation method:
function geraTeste($clientes){
$code = "<!DOCTYPE html>
<html>
<head>
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>nome</td>
<td>CPF/CNPJ</td>
<td>IE</td>
</tr>";
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>
</html>";
return $code;
}
$clientes = Cliente::all();
$pdf = \App::make('dompdf.wrapper');
$pdf->loadHTML(geraTeste($clientes));
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();
$pdf->loadHTML($view);
$pdf->stream();
//return $pdf->stream('invoice');
return $pdf->download('profile.pdf');
If anyone can help, I accept suggestions…
Answer:
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.