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;
9
throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
13
* PHPExcel_Writer_PDF_tcPDF
15
* Copyright (c) 2006 - 2015 PHPExcel
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.
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.
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
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##
37
class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
40
* Create a new PHPExcel_Writer_PDF
42
* @param PHPExcel $phpExcel PHPExcel object
44
public function __construct(PHPExcel $phpExcel)
46
parent::__construct($phpExcel);
50
* Save PHPExcel to file
52
* @param string $pFilename Name of the file to save as
53
* @throws PHPExcel_Writer_Exception
55
public function save($pFilename = null)
57
$fileHandle = parent::prepareForSave($pFilename);
59
// Default PDF paper size
60
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
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();
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();
75
// Override Page Orientation
76
if (!is_null($this->getOrientation())) {
77
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
81
// Override Paper Size
82
if (!is_null($this->getPaperSize())) {
83
$printPaperSize = $this->getPaperSize();
86
if (isset(self::$paperSizes[$printPaperSize])) {
87
$paperSize = self::$paperSizes[$printPaperSize];
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);
98
$pdf->setPrintHeader(false);
99
$pdf->setPrintFooter(false);
103
// Set the appropriate font
104
$pdf->SetFont($this->getFont());
106
$this->generateHTMLHeader(false) .
107
$this->generateSheetData() .
108
$this->generateHTMLFooter()
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());
119
fwrite($fileHandle, $pdf->output($pFilename, 'S'));
121
parent::restoreStateAfterSave($fileHandle);