php - converting excel file to pdf with phpexcel returning empty file -


i have excel file , want convert file pdf using php excel. using following code:

namespace frontend\controllers; use phpexcel; use phpexcel_iofactory; use phpexcel_settings; use phpexcel_style_alignment; use yii\web\controller;  class exportscontroller extends controller {     public function actionindex()     {         $inputfile = \yii::getalias('@frontend') . '/controllers/matrix.xls';         $inputfiletype = phpexcel_iofactory::identify($inputfile);         $objreader = phpexcel_iofactory::createreader($inputfiletype);         $objphpexcel = $objreader->load($inputfile);         $objphpexcel->setactivesheetindex(0);          $rendererlibrary = 'dompdf';         $rendererlibrarypath = \yii::getalias('@frontend') . '/components/classes/phpexcel/writer/pdf/' . $rendererlibrary;         $rendererlibrarypath .= '.php';          if (!phpexcel_settings::setpdfrenderer(             $rendererlibrary,             $rendererlibrarypath         )         ) {             die(                 'notice: please set $renderername , $rendererlibrarypath values' .                 '<br />' .                 'at top of script appropriate directory structure'             );         }         header('content-type: application/pdf');         header('content-disposition: attachment;filename="01simple.pdf"');         header('cache-control: max-age=0');         $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'pdf');         $objwriter->save('php://output');     } } 

when comment last 2 lines of code returning empty pdf file otherwise throwing following error: net::err_invalid_response.

could please me find mistake of code?

add code in last

  header('content-type: application/pdf');   header('content-disposition: attachment;filename="01simple.pdf"');   header('cache-control: max-age=0');   $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'pdf');   ob_end_clean();   $objwriter->save('php://output'); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -