Search code examples
phpjqueryyiifpdf

FPDF, Yii and jQuery not working


I'm using jQuery to post data to a Yii controller action that'll render a pdf. But facing some issues.

nom = "toto";
$.post(baseUrl+'print/recufrais',{"NomFichier" : nom+'.pdf', "id": code},
    function(responde)
    {
        console.log(responde);
    }
);

And the log is :

%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream x�e�MN�0��=���b<Ώ���dZ�� �@BlXq-��-�S$�"y��͛7 trailer << /Size 9 /Root 8 0 R /Info 7 0 R > startxref 987 %%EOF

The action is as follows :

public function actionRecufrais()
{
    //header('Content-type: application/pdf');
    $NomFichier = $_POST['NomFichier'];
    $PDF=New phpToPDF();
    $PDF->FPDF('P');
    $PDF->AddPage();

    $PDF->SetFont('Courier','B','15');//$PDF->SetXY(60, 47);
    $PDF->Ln(); 

    $PDF->MultiCell(0, 15, iconv("UTF-8", "windows-1252", "RECU DE REGLEMENT"), 0, "C", 0);

    $PDF->SetFont('Courier', 'B', '11');
    $PDF->MultiCell(0, 15, iconv("UTF-8", "windows-1252", "NOM ET PRENOMS DE L'ELEVE : "), 0, 'L', 0);


    $PDF->Output($NomFichier, 'F');
    $PDF->Output($NomFichier, 'D');
}

Is there something going wrong with my code ?


Solution

  • Oh no. A dependence is missing : require_once 'tools/php/functions.php'; $NomFichier = "etats/recufrais/" .$_POST['NomFichier'];

    inside my controller action. Thanks for your attention.