php PHPExcel 保存PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21599221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPExcel Save PDF
提问by napster3world
Help me i want to save excel in pdf format The code:
帮我我想以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');
I want to save in pdf format, but when i try to save i have an error response from phpexcel:
Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Unable to load PDF Rendering library' in C:\xampp\htdocs\fserv\Classes\PHPExcel\Writer\PDF\DomPDF.php:34 Stack trace: #0 C:\xampp\htdocs\fserv\esportatore.php(190): include_once() #1 C:\xampp\htdocs\fserv\index.php(44): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\fserv\Classes\PHPExcel\Writer\PDF\DomPDF.phpon line 34
我想以 pdf 格式保存,但是当我尝试保存时,我收到了来自 phpexcel 的错误响应:
致命错误:未捕获的异常“PHPExcel_Writer_Exception”与消息“无法加载 PDF 渲染库”在 C:\xampp\htdocs\fserv\ Classes\PHPExcel\Writer\PDF\DomPDF.php:34 Stack trace: #0 C:\xampp\htdocs\fserv\esportatore.php(190): include_once() #1 C:\xampp\htdocs\fserv\index.php php(44): include('C:\xampp\htdocs...') #2 {main} 被抛出到C:\xampp\htdocs\fserv\Classes\PHPExcel\Writer\PDF\DomPDF.php第34行
回答by Ruben
You need DomPDF for rendering the PDF. Check if you have the DomPDF library, otherwise download and implement it as follow:
您需要 DomPDF 来呈现 PDF。检查你是否有DomPDF库,否则下载并实现如下:
$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF;
$rendererLibrary = 'domPDF0.6.0beta3';
$rendererLibraryPath = dirname(__FILE__). 'libs/classes/dompdf' . $rendererLibrary;

