Error generating PDF in CakePHP via FPDF

0

I am rewriting a legacy system from the company I work in (using CakePHP for this) and it generates some PDF reports using FPDF. However, in CakePHP I can not generate any PDF.

Follow 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, just the Chrome PDF plugin and it says "loading" but never loads.

It is not a problem on the server because, on the same test server, there is an old system mirror running normally.

    
asked by anonymous 23.01.2015 / 17:30

2 answers

0

The error was in the Layout (pdf) I was using, in the end it was all right with the action and the view, what was missing was a part of the code. I needed to echo the contents through the $content_for_layout; variable and I had not attempted this.

Thank you all for the support.

    
29.01.2015 / 17:23
1

Is it possible to migrate to HtmlToPDF? If so, do this migration. I also had several problems with the FPDF that I was only able to solve with the migration.

In addition, open the Chrome development tools (CTRL + J) and the Network (or Network) tab, check what is being loaded when trying to generate the pdf.

    
26.01.2015 / 14:46