Search code examples
phpcakephppdffpdf

cakephp 3 and fpdf cannot render pdf in form of a view


**Controller**                  : Test
**View where the form resides** : index.ctp
**View containing fpdf code**   : pdf.ctp

I generate a pdf file using FPDF but the pdf file is not rendering properly. I have confirmed that the FPDF code is error free.

On URL

localhost/project/test

I will fill up a form and press submit. This will submit to

localhost/project/test/pdf

But here the pdf is not rendering properly. It just keeps on telling Loading.

If i submit it to some other folder/pdf.php file (same fpdf code in php file) Everything is ok

localhost/fpdf/pdf.php

Solution

  • I'm answering my questions myself. Come on people HELP ME!!

    The problem was that the output was not rendering as pdf. I used this controller to solve my problem.

    public function pdf()
    {
        $this->response->type('pdf');
    }