使用PHPExcel和DomPDF生成PDF

时间:2017-11-24 04:02:30

标签: php pdf phpexcel dompdf

我正在尝试使用PHPExcel和DomPDF从Excel文件生成PDF。我在这里尝试了所有示例和答案,但我的setPdfRenderer仍然存在问题。因为我跑步时会显示通知文字。

到目前为止,这是代码。

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/'.$rendererLibrary;

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: attachement;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->save(str_replace('summaryOnLateReportSubmissions.php', 'export/' . $filename . '.pdf', __FILE__));
return true;

}

0 个答案:

没有答案