[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

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

   1  <?php
   2  
   3  /**  Require mPDF library */
   4  $pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/mpdf.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_mPDF
  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_mPDF 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          $this->setOrientation($orientation);
  74  
  75          //  Override Page Orientation
  76          if (!is_null($this->getOrientation())) {
  77              $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
  78                  ? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT
  79                  : $this->getOrientation();
  80          }
  81          $orientation = strtoupper($orientation);
  82  
  83          //  Override Paper Size
  84          if (!is_null($this->getPaperSize())) {
  85              $printPaperSize = $this->getPaperSize();
  86          }
  87  
  88          if (isset(self::$paperSizes[$printPaperSize])) {
  89              $paperSize = self::$paperSizes[$printPaperSize];
  90          }
  91  
  92  
  93          //  Create PDF
  94          $pdf = new mpdf();
  95          $ortmp = $orientation;
  96          $pdf->_setPageSize(strtoupper($paperSize), $ortmp);
  97          $pdf->DefOrientation = $orientation;
  98          $pdf->AddPage($orientation);
  99  
 100          //  Document info
 101          $pdf->SetTitle($this->phpExcel->getProperties()->getTitle());
 102          $pdf->SetAuthor($this->phpExcel->getProperties()->getCreator());
 103          $pdf->SetSubject($this->phpExcel->getProperties()->getSubject());
 104          $pdf->SetKeywords($this->phpExcel->getProperties()->getKeywords());
 105          $pdf->SetCreator($this->phpExcel->getProperties()->getCreator());
 106  
 107          $pdf->WriteHTML(
 108              $this->generateHTMLHeader(false) .
 109              $this->generateSheetData() .
 110              $this->generateHTMLFooter()
 111          );
 112  
 113          //  Write to file
 114          fwrite($fileHandle, $pdf->Output('', 'S'));
 115  
 116          parent::restoreStateAfterSave($fileHandle);
 117      }
 118  }


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