diff --git a/Tests/01simple-download-pdf.php b/Tests/01simple-download-pdf.php index 55f7e1b..dccbcd0 100644 --- a/Tests/01simple-download-pdf.php +++ b/Tests/01simple-download-pdf.php @@ -34,6 +34,17 @@ date_default_timezone_set('Europe/London'); require_once '../Classes/PHPExcel.php'; +// Change these values to select the Rendering library that you wish to use +// and its directory location on your server +//$rendererName = PHPExcel_Settings::PDF_RENDERER_TCPDF; +$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF; +//$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; +//$rendererLibrary = 'tcPDF5.9'; +$rendererLibrary = 'mPDF5.4'; +//$rendererLibrary = 'domPDF0.6.0beta3'; +$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary; + + // Create new PHPExcel object $objPHPExcel = new PHPExcel(); @@ -61,12 +72,24 @@ $objPHPExcel->setActiveSheetIndex(0) // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('Simple'); - +$objPHPExcel->getActiveSheet()->setShowGridLines(false); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); +if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + PHP_EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + // Redirect output to a client’s web browser (PDF) header('Content-Type: application/pdf'); header('Content-Disposition: attachment;filename="01simple.pdf"'); diff --git a/Tests/21pdf.php b/Tests/21pdf.php index d104227..ddfd99f 100644 --- a/Tests/21pdf.php +++ b/Tests/21pdf.php @@ -36,17 +36,41 @@ include "05featuredemo.inc.php"; require_once '../Classes/PHPExcel/IOFactory.php'; +// Change these values to select the Rendering library that you wish to use +// and its directory location on your server +//$rendererName = PHPExcel_Settings::PDF_RENDERER_MPDF; +$rendererName = PHPExcel_Settings::PDF_RENDERER_DOMPDF; +//$rendererLibrary = 'tcPDF5.9'; +//$rendererLibrary = 'mPDF5.4'; +$rendererLibrary = 'domPDF0.6.0beta3'; +$rendererLibraryPath = dirname(__FILE__).'/../../../libraries/PDF/' . $rendererLibrary; + + echo date('H:i:s') , " Hide grid lines" , PHP_EOL; $objPHPExcel->getActiveSheet()->setShowGridLines(false); echo date('H:i:s') , " Set orientation to landscape" , PHP_EOL; $objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE); -echo date('H:i:s') , " Write to PDF format" , PHP_EOL; + +echo date('H:i:s') , " Write to PDF format using {$rendererName}" , PHP_EOL; + +if (!PHPExcel_Settings::setPdfRenderer( + $rendererName, + $rendererLibraryPath + )) { + die( + 'NOTICE: Please set the $rendererName and $rendererLibraryPath values' . + PHP_EOL . + 'at the top of this script as appropriate for your directory structure' + ); +} + + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF'); $objWriter->setSheetIndex(0); -$objWriter->save(str_replace('.php', '.pdf', __FILE__)); -echo date('H:i:s') , " File written to " , str_replace('.php', '.pdf', __FILE__) , PHP_EOL; +$objWriter->save(str_replace('.php', '_'.$rendererName.'.pdf', __FILE__)); +echo date('H:i:s') , " File written to " , str_replace('.php', '_'.$rendererName.'.pdf', __FILE__) , PHP_EOL; // Echo memory peak usage