I use the software laragon that already comes with laravel and composer integrated to the project, I executed the line:
Note: I did not bother with good practice yet, I want to make it work first
composer require barryvdh/laravel-dompdf
To install the PDF generation API. I added the following lines in the file of the / config app.php folder
On providers
Barryvdh\DomPDF\ServiceProvider::class,
In aliases
'PDF' => Barryvdh\DomPDF\Facade::class,
I imported into the class where the pdf generation method is
use PDF;
In the code I already used in several ways and none 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');
In 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');
That too:
$pdf = PDF::loadView('Pdf.PdfClientesReport2', $clientes);
return $pdf->download('invoice.pdf');
I got this way now, but I wanted to be able to open it on my own browser.
$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 someone can help, I accept your questions ..