[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** Require tcPDF library */ 4 $pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/tcpdf.php'; 5 if (file_exists($pdfRendererClassFile)) { 6 $k_path_url = PHPExcel_Settings::getPdfRendererPath(); 7 require_once $pdfRendererClassFile; 8 } else { 9 throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library'); 10 } 11 12 /** 13 * PHPExcel_Writer_PDF_tcPDF 14 * 15 * Copyright (c) 2006 - 2015 PHPExcel 16 * 17 * This library is free software; you can redistribute it and/or 18 * modify it under the terms of the GNU Lesser General Public 19 * License as published by the Free Software Foundation; either 20 * version 2.1 of the License, or (at your option) any later version. 21 * 22 * This library is distributed in the hope that it will be useful, 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 * Lesser General Public License for more details. 26 * 27 * You should have received a copy of the GNU Lesser General Public 28 * License along with this library; if not, write to the Free Software 29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 30 * 31 * @category PHPExcel 32 * @package PHPExcel_Writer_PDF 33 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) 34 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL 35 * @version ##VERSION##, ##DATE## 36 */ 37 class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter 38 { 39 /** 40 * Create a new PHPExcel_Writer_PDF 41 * 42 * @param PHPExcel $phpExcel PHPExcel object 43 */ 44 public function __construct(PHPExcel $phpExcel) 45 { 46 parent::__construct($phpExcel); 47 } 48 49 /** 50 * Save PHPExcel to file 51 * 52 * @param string $pFilename Name of the file to save as 53 * @throws PHPExcel_Writer_Exception 54 */ 55 public function save($pFilename = null) 56 { 57 $fileHandle = parent::prepareForSave($pFilename); 58 59 // Default PDF paper size 60 $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) 61 62 // Check for paper size and page orientation 63 if (is_null($this->getSheetIndex())) { 64 $orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation() 65 == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; 66 $printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); 67 $printMargins = $this->phpExcel->getSheet(0)->getPageMargins(); 68 } else { 69 $orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() 70 == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; 71 $printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); 72 $printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); 73 } 74 75 // Override Page Orientation 76 if (!is_null($this->getOrientation())) { 77 $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) 78 ? 'L' 79 : 'P'; 80 } 81 // Override Paper Size 82 if (!is_null($this->getPaperSize())) { 83 $printPaperSize = $this->getPaperSize(); 84 } 85 86 if (isset(self::$paperSizes[$printPaperSize])) { 87 $paperSize = self::$paperSizes[$printPaperSize]; 88 } 89 90 91 // Create PDF 92 $pdf = new TCPDF($orientation, 'pt', $paperSize); 93 $pdf->setFontSubsetting(false); 94 // Set margins, converting inches to points (using 72 dpi) 95 $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72); 96 $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72); 97 98 $pdf->setPrintHeader(false); 99 $pdf->setPrintFooter(false); 100 101 $pdf->AddPage(); 102 103 // Set the appropriate font 104 $pdf->SetFont($this->getFont()); 105 $pdf->writeHTML( 106 $this->generateHTMLHeader(false) . 107 $this->generateSheetData() . 108 $this->generateHTMLFooter() 109 ); 110 111 // Document info 112 $pdf->SetTitle($this->phpExcel->getProperties()->getTitle()); 113 $pdf->SetAuthor($this->phpExcel->getProperties()->getCreator()); 114 $pdf->SetSubject($this->phpExcel->getProperties()->getSubject()); 115 $pdf->SetKeywords($this->phpExcel->getProperties()->getKeywords()); 116 $pdf->SetCreator($this->phpExcel->getProperties()->getCreator()); 117 118 // Write to file 119 fwrite($fileHandle, $pdf->output($pFilename, 'S')); 120 121 parent::restoreStateAfterSave($fileHandle); 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |