PHPExcel保存PDF

时间:2014-02-06 09:48:12

标签: php pdf phpexcel

帮助我,我想以pdf格式保存excel 代码:

include_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory */
require_once ('Classes/PHPExcel/IOFactory.php');
include_once ('Classes/PHPExcel/Writer/Excel2007.php');
include_once ('Classes/PHPExcel/Writer/PDF.php');

include_once ('Classes/PHPExcel/Writer/PDF/DomPDF.php');


$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
//$rendererLibrary = 'tcPDF5.9';
//$rendererLibrary = 'mPDF5.4';
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = '/' . $rendererLibrary;
$objPHPExcel->getActiveSheet()->setTitle('Orari');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(0);
$objWriter->save('esp.pdf');

我想以pdf格式保存,但是当我尝试保存时,我有来自phpexcel的错误响应: 致命错误:在C:\ xampp \ htdocs \ fserv \ Classes \ PHPExcel \ Writer \ PDF \ DomPDF.php中显示消息'无法加载PDF渲染库'的未捕获异常'PHPExcel_Writer_Exception':34堆栈跟踪:#0 C:\ xampp \ htdocs \ fserv \ esportatore.php(190):include_once()#1 C:\ xampp \ htdocs \ fserv \ index.php(44):include('C:\ xampp \ htdocs。 ..')在 34
C:C:\ xampp \ htdocs \ fserv \ Classes \ PHPExcel \ Writer \ PDF \ DomPDF.php 中抛出#2 {main} />

1 个答案:

答案 0 :(得分:8)

您需要DomPDF才能呈现PDF。检查您是否拥有DomPDF库,否则请按照以下步骤下载并实施:

$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary;