0
I’m rewriting a legacy system of the company I work on (using Cakephp for this) and it generates some PDF reports using FPDF. However, in Cakephp I cannot generate any PDF.
Follows the code
Action
function pdf ($id = null) {
App::import('Vendor', 'Fpdf', array('file' => 'fpdf/fpdf.php'));
$this->layout = 'pdf';
$this->set('fpdf', new FPDF('P','mm','A4'));
$mensagem = is_null($id) ? "Nenhum ID fornecido" : "ID: $id";
$this->set('data', $mensagem);
$this->response->type('pdf');
$this->render('pdf');
}
View
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10, $data);
$fpdf->Output();
No error appears, only the Chrome PDF plugin and is written "loading" but never loads.
There is no problem on the server because, in the same test server, has a mirror of the old system working normally.
What is the error generated?
– André Ribeiro
None, the pdf plugin of Chrome appears and is just loading, if I give Ctrl+s comes an empty document. Thanks for the touch
– rafaslide
Can it take time to load and/or build the PDF? There is a way for you to debug to see how the execution occurs?
– mutlei
You’re calling
$fpdf->Output()
in your view?– André Ribeiro
I would like to see the View code too so I can try to reproduce the problem
– Erlon Charles
@Mutley is not slow, it stays like this forever. I also tried to use debug but nothing came out.
– rafaslide
@Andréribeiro I am
– rafaslide
@Erloncharles
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10, $data);
$fpdf->Output();
– rafaslide
A pdf document is returned valid but empty or an empty file?
– André Ribeiro
@Andréribeiro comes an empty file.
– rafaslide
@rafaslide try to add a
error_reporting(E_ALL)
at the beginning of its action just to see if theFPDF
generates some error that is not being shown.– André Ribeiro