PHPExcel_Writer
[ class tree: PHPExcel_Writer ] [ index: PHPExcel_Writer ] [ all elements ]

Source for file PDF.php

Documentation is available at PDF.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Writer
  23.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.7, 2009-04-22
  26.  */
  27.  
  28.  
  29. /** PHPExcel_IWriter */
  30. require_once 'PHPExcel/Writer/IWriter.php';
  31.  
  32. /** PHPExcel_Writer_HTML */
  33. require_once 'PHPExcel/Writer/HTML.php';
  34.  
  35. /** PHPExcel_Cell */
  36. require_once 'PHPExcel/Cell.php';
  37.  
  38. /** PHPExcel_RichText */
  39. require_once 'PHPExcel/RichText.php';
  40.  
  41. /** PHPExcel_Shared_Drawing */
  42. require_once 'PHPExcel/Shared/Drawing.php';
  43.  
  44. /** PHPExcel_HashTable */
  45. require_once 'PHPExcel/HashTable.php';
  46.  
  47. /** PHPExcel_Shared_PDF */
  48. require_once 'PHPExcel/Shared/PDF.php';
  49.  
  50.  
  51. /**
  52.  * PHPExcel_Writer_PDF
  53.  *
  54.  * @category   PHPExcel
  55.  * @package    PHPExcel_Writer
  56.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  57.  */
  58.     /**
  59.      * Temporary storage directory
  60.      *
  61.      * @var string 
  62.      */
  63.     private $_tempDir = '';
  64.  
  65.     /**
  66.      * Create a new PHPExcel_Writer_PDF
  67.      *
  68.      * @param     PHPExcel    $phpExcel    PHPExcel object
  69.      */
  70.     public function __construct(PHPExcel $phpExcel{
  71.         parent::__construct($phpExcel);
  72.         $this->setUseInlineCss(true);
  73.         $this->_tempDir = sys_get_temp_dir();
  74.     }
  75.  
  76.     /**
  77.      * Save PHPExcel to file
  78.      *
  79.      * @param     string         $pFileName 
  80.      * @throws     Exception
  81.      */
  82.     public function save($pFilename null{
  83.         $saveArrayReturnType PHPExcel_Calculation::getArrayReturnType();
  84.         PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
  85.  
  86.         // Open file
  87.         $fileHandle fopen($pFilename'w');
  88.         if ($fileHandle === false{
  89.             throw new Exception("Could not open file $pFilename for writing.");
  90.         }
  91.  
  92.         // Build CSS
  93.         $this->buildCSS(true);
  94.  
  95.         // Generate HTML
  96.         $html '';
  97.         //$html .= $this->generateHTMLHeader(false);
  98.         $html .= $this->generateSheetData();
  99.         //$html .= $this->generateHTMLFooter();
  100.  
  101.         // Default PDF paper size
  102.         $paperSize 'A4';
  103.         $orientation 'P';
  104.                 
  105.         // Check for overrides
  106.         if (is_null($this->getSheetIndex())) {
  107.             $orientation $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation(== 'landscape' 'L' 'P';
  108.         else {
  109.             $orientation $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation(== 'landscape' 'L' 'P';
  110.         }
  111.  
  112.         // Create PDF
  113.         $pdf new TCPDF($orientation'pt'$paperSize);
  114.         $pdf->AddPage();
  115.         $pdf->SetFont('freesans');
  116.         $pdf->writeHTML($html);
  117.  
  118.         // Document info
  119.         $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
  120.         $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
  121.         $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
  122.         $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
  123.         $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
  124.  
  125.         // Write to file
  126.         fwrite($fileHandle$pdf->output($pFilename'S'));
  127.  
  128.         // Close file
  129.         fclose($fileHandle);
  130.  
  131.         PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
  132.     }
  133.  
  134.     /**
  135.      * Get temporary storage directory
  136.      *
  137.      * @return string 
  138.      */
  139.     public function getTempDir({
  140.         return $this->_tempDir;
  141.     }
  142.  
  143.     /**
  144.      * Set temporary storage directory
  145.      *
  146.      * @param     string    $pValue        Temporary storage directory
  147.      * @throws     Exception    Exception when directory does not exist
  148.      */
  149.     public function setTempDir($pValue ''{
  150.         if (is_dir($pValue)) {
  151.             $this->_tempDir = $pValue;
  152.         else {
  153.             throw new Exception("Directory does not exist: $pValue");
  154.         }
  155.     }
  156. }

Documentation generated on Wed, 22 Apr 2009 09:01:27 +0200 by phpDocumentor 1.4.1