3
I use the laragon software that already comes with Windows and integrated Composer to the project, ran the line:
Note: I have not preoccupied myself with good practices yet, I want to make it work first
composer require barryvdh/laravel-dompdf
To install the PDF generation api. I added the following lines to the /config app.php folder file
In providers
Barryvdh\DomPDF\ServiceProvider::class,
In aliases
'PDF' => Barryvdh\DomPDF\Facade::class,
I imported in the class where the pdf generation method is
use PDF;
In the code I have used 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');
Thus 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();
That way too:
$pdf = PDF::loadView('Pdf.PdfClientesReport2', compact('clientes'));
return $pdf->download('invoice.pdf');
Of this also:
$pdf = PDF::loadView('Pdf.PdfClientesReport2', $clientes);
return $pdf->download('invoice.pdf');
I got it that way a little while ago, but I wish I could 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’ll take dirt..
Galera good afternoon in my case, I’m using angular4 on the front and Laravel on the backend, when I consult the api Readable by Postman, I can download the PDF, when I do the HTTP request at the angle it returns me positive plus the download window does not open to download the file can help me
– Carlos Alexandre R Ramos