Generate PDF using jquery ajax -
i working phalcon php framework. want send data displayed in div tag(it result of search)to controller function, , controller generate pdf file. but, pdf file not generating. here 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 code 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 see generated pdf file in way of warking
look @ tcpdf @ http://www.tcpdf.org/ pdf library works phalcon. while not phalcon specific question (since phalcon doesn't have native pdf library), can integrate in phalcon. if wanted that, register tcpdf library service phalcon , include library in autoloader other service.
example:
$di->set('tcpdf', function() { $tcpdf = new tcpdf(); return $tcpdf; });
which make library accessible by
$this->tcpdf
in object extends core phalcon functionality or
\phalcon\di::getdefault()->gettcpdf();
statically.
Comments
Post a Comment