0
I’m trying to generate a PDF from a view
, and it’s working, however, when I call the route to call the controller
, the upload is for several seconds, even minutes to generate the PDF, and download, not to mention not applying my CSS styles. I’d like a light, to know what I can do.
PS: use another library, only if it is simpler.
View:
<!doctype html>
<html lang="pt-BR">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css">
<title>Lista de chamada</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading text-center">
<h4>Lista de chamada</h4>
</div>
<div class="panel-body text-center">
<table class="table table-striped">
<thead>
<th>#</th>
<th>Cartão SUS</th>
<th>Data de nascimento</th>
<th>Avaliação alterada</th>
<th>Peso</th>
<th>Altura</th>
<th>Assinatura</th>
</thead>
<tbody>
@foreach($pacientes as $paciente)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $paciente->NumeroCartaoSUS }}</td>
<td>{{ $paciente->DataNascimento }}</td>
<td>{!!
$paciente->AvaliacaoAlterada == 1 ?
Icon::ok().' Sim' :
Icon::remove().' Não'
!!}
</td>
<td>{{ $paciente->Peso }}</td>
<td>{{ $paciente->Altura }}</td>
<td> </td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Controller:
<?php
namespace Famerp\Http\Controllers\PDF;
use PDF;
use Famerp\Models\Paciente;
use Famerp\Http\Controllers\Controller;
class PDFController extends Controller
{
public function pdfListaChamada()
{
$pacientes = Paciente::all();
$pdf = PDF::loadView('pdf.pdf-lista-chamada', array('pacientes' => $pacientes));
return $pdf->setPaper('a4')->download('lista-chamada.pdf');
}
}
I followed the code guidelines you have on the GitHub
of the project, I do not understand why.
Do you have an address for that code? I think CSS and Font have some settings and the generation time is also very high due maybe factors that we can not play
– novic
Project Github has a correct link? which link is?
– novic
This is the link to the PDF project: https://github.com/barryvdh/laravel-dompdf The link to my project is: https://github.com/matheuspicioli/famerp
– Matheus Picioli
Do you have many patients? This link is supported by CSS https://github.com/dompdf/dompdf/wiki/CSSCompatibility
– novic
Really looking like this, not knowing what happens on your machine seems correct, the code is small and clean, but, will know why the problem, is that there is no way to reproduce, is a local problem maybe.
– novic
Ta wait a minute, put the table in git then. I’m on hold.
– novic
figured out the problem
– novic
And what is it? It’s involving environment itself?
– Matheus Picioli
The css file, it is not accepting, should ai have a reason. mainly because of the remove fonts
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css">
of your fileView
and testing– novic
Now it’s working, but why doesn’t it recognize my css?
– Matheus Picioli
Because it is not yours it is of a framework and the same is not compatible with the algorithm of the pdf generator. The sources for example are some as described in the documentation.
– novic
So to apply a CSS, I need to remove the sources from it, or just use the relative path, instead of the function that Laravel provides me?
– Matheus Picioli
You have to use the fonts and css compatible with the package, and in it it is explained that... understood? That CSS is no use!
– novic
It was solved by taking out the function Asset() and calling through the same relative path, this solved the PDF generation time, but the source glyphicon were not possible to load them. Thank you!!
– Matheus Picioli