[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/phpexcel/PHPExcel/Writer/PDF/ -> DomPDF.php (source)

   1  <?php
   2  
   3  /**  Require DomPDF library */
   4  $pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/dompdf_config.inc.php';
   5  if (file_exists($pdfRendererClassFile)) {
   6      require_once $pdfRendererClassFile;
   7  } else {
   8      throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
   9  }
  10  
  11  /**
  12   *  PHPExcel_Writer_PDF_DomPDF
  13   *
  14   *  Copyright (c) 2006 - 2015 PHPExcel
  15   *
  16   *  This library is free software; you can redistribute it and/or
  17   *  modify it under the terms of the GNU Lesser General Public
  18   *  License as published by the Free Software Foundation; either
  19   *  version 2.1 of the License, or (at your option) any later version.
  20   *
  21   *  This library is distributed in the hope that it will be useful,
  22   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  23   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  24   *  Lesser General Public License for more details.
  25   *
  26   *  You should have received a copy of the GNU Lesser General Public
  27   *  License along with this library; if not, write to the Free Software
  28   *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  29   *
  30   *  @category    PHPExcel
  31   *  @package     PHPExcel_Writer_PDF
  32   *  @copyright   Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  33   *  @license     http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  34   *  @version     ##VERSION##, ##DATE##
  35   */
  36  class PHPExcel_Writer_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
  37  {
  38      /**
  39       *  Create a new PHPExcel_Writer_PDF
  40       *
  41       *  @param   PHPExcel    $phpExcel    PHPExcel object
  42       */
  43      public function __construct(PHPExcel $phpExcel)
  44      {
  45          parent::__construct($phpExcel);
  46      }
  47  
  48      /**
  49       *  Save PHPExcel to file
  50       *
  51       *  @param   string     $pFilename   Name of the file to save as
  52       *  @throws  PHPExcel_Writer_Exception
  53       */
  54      public function save($pFilename = null)
  55      {
  56          $fileHandle = parent::prepareForSave($pFilename);
  57  
  58          //  Default PDF paper size
  59          $paperSize = 'LETTER';    //    Letter    (8.5 in. by 11 in.)
  60  
  61          //  Check for paper size and page orientation
  62          if (is_null($this->getSheetIndex())) {
  63              $orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation()
  64                  == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
  65              $printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
  66              $printMargins = $this->phpExcel->getSheet(0)->getPageMargins();
  67          } else {
  68              $orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
  69                  == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
  70              $printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
  71              $printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
  72          }
  73          
  74          $orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
  75  
  76          //  Override Page Orientation
  77          if (!is_null($this->getOrientation())) {
  78              $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
  79                  ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
  80                  : $this->getOrientation();
  81          }
  82          //  Override Paper Size
  83          if (!is_null($this->getPaperSize())) {
  84              $printPaperSize = $this->getPaperSize();
  85          }
  86  
  87          if (isset(self::$paperSizes[$printPaperSize])) {
  88              $paperSize = self::$paperSizes[$printPaperSize];
  89          }
  90  
  91  
  92          //  Create PDF
  93          $pdf = new DOMPDF();
  94          $pdf->set_paper(strtolower($paperSize), $orientation);
  95  
  96          $pdf->load_html(
  97              $this->generateHTMLHeader(false) .
  98              $this->generateSheetData() .
  99              $this->generateHTMLFooter()
 100          );
 101          $pdf->render();
 102  
 103          //  Write to file
 104          fwrite($fileHandle, $pdf->output());
 105  
 106          parent::restoreStateAfterSave($fileHandle);
 107      }
 108  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1