PHPExcel和domPDF没有生成文件

时间:2017-11-17 02:54:06

标签: php export phpexcel dompdf

我正在尝试使用PHPExcel生成excel文件,并使用domPDF将其转换为PDF。错误是500

到目前为止,这是我的代码。

    function createPDF($filename){



   //PHPExcel
   require_once dirname(__FILE__) . '/plugin/PHPExcel/IOFactory.php';

   $inputFile = dirname(__FILE__) . '/export/'.$filename.'.xls';
   $inputFileType = PHPExcel_IOFactory::identify($inputFile);
   $objReader = PHPExcel_IOFactory::createReader($inputFileType);
   $objPHPExcel = $objReader->load($inputFile);
   $objPHPExcel->setActiveSheetIndex(0);

   $rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
   $rendererLibrary = 'dompdf';
   $rendererLibraryPath = dirname(__FILE__) . '/plugin/dompdf/'.$rendererLibrary;
   $rendererLibraryPath .= '.php';

   var_dump($rendererLibraryPath);

   if (!PHPExcel_Settings::setPdfRenderer($rendererLibrary,$rendererLibraryPath)){
    die(
        'NOTICE: Please set the $rendererName and $rendererLibraryPath values' .
        '<br />' .
        'at the top of this script as appropriate for your 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');
   ob_end_clean();
   $objWriter->save(str_replace('summaryOnLateReportSubmissions.php', 'export/' . $filename . '.pdf', __FILE__));
   return true;
}

我似乎无法解决这个问题超过一天了。 TIA

0 个答案:

没有答案