From 3edd3c30e38990b74db294af3433de896eee798d Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 5 Jun 2012 14:17:36 +0000 Subject: [PATCH] Update /Tests files for PDF writer to use new configuration settings git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@91352 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Tests/01simple-download-pdf.php | 25 ++++++++++++++++++++++++- Tests/21pdf.php | 30 +++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Tests/01simple-download-pdf.php b/Tests/01simple-download-pdf.php index 55f7e1b2..dccbcd04 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 d1042279..ddfd99fa 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