We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Generate PDF using jquery ajax

i am working with phalcon php framework. I want to send data displayed in a div tag(it is a result of a search)to controller function, and controller will generate pdf file. But, pdf file is not generating. Here is my view:

  var imenica = "Ja se zovem Nedim Omerbegovic";
       $.ajax({
        url: '<?php echo  $this->url->get("test/creatingpdf");?>',
        type: 'POST',
        dataType: '',
        data: {imenica:imenica},
        success: function(data){
            alert(data);
            } ,
            error: function(){
                alert("Greska");
            }

    });
});

and here is code for controller:

public function creatingpdfAction(){
    $this->view->disable();
    $string =$_POST['imenica'];
    $this->view->setVars(array('ime'=>$string));

          $loader = new \Phalcon\Loader();
    $loader->registerClasses(
     array(
    "mpdf"=> "C:/wamp/www/phalcon1/mpdf/mpdf.php"
 )
 );

    $loader->register();
    //$string = "Ja se zovem Nedim Omerbegovic";
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');
    $cont = $this->view->getRender('test', 'creatingpdf');
    //generisanje pdf dokumenta
    $pdf = new mpdf();
    $pdf->WriteHTML($cont, 2);
    $br = rand(0,100000);
    $ispis = "Pobjeda Rudet-Izvjestaj-".$br;
    $pdf->Output($ispis, 'I');
  }

How can i see generated pdf file in this way of warking. Please, if anyone knows help me.

Hi there To generate pdf files using code is so difficult for me.However ,i usually do the pdf generating using this program: https://www.rasteredge.com/how-to/csharp-imaging/pdf-processing/ It's very convenient to process pdf files.Hope to help you.