Subversion Repositories eFlore/Applications.cel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2388 jpm 1
<?php
2
/**
3
 *  PHPExcel
4
 *
5
 *  Copyright (c) 2006 - 2013 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_PDF
23
 *  @copyright   Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
24
 *  @license     http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25
 *  @version     ##VERSION##, ##DATE##
26
 */
27
 
28
 
29
/**  Require tcPDF library */
30
$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/tcpdf.php';
31
if (file_exists($pdfRendererClassFile)) {
32
    $k_path_url = PHPExcel_Settings::getPdfRendererPath();
33
    require_once $pdfRendererClassFile;
34
} else {
35
    throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
36
}
37
 
38
/**
39
 *  PHPExcel_Writer_PDF_tcPDF
40
 *
41
 *  @category    PHPExcel
42
 *  @package     PHPExcel_Writer_PDF
43
 *  @copyright   Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
44
 */
45
class PHPExcel_Writer_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter
46
{
47
    /**
48
     *  Create a new PHPExcel_Writer_PDF
49
     *
50
     *  @param  PHPExcel  $phpExcel  PHPExcel object
51
     */
52
    public function __construct(PHPExcel $phpExcel)
53
    {
54
        parent::__construct($phpExcel);
55
    }
56
 
57
    /**
58
     *  Save PHPExcel to file
59
     *
60
     *  @param     string     $pFilename   Name of the file to save as
61
     *  @throws    PHPExcel_Writer_Exception
62
     */
63
    public function save($pFilename = NULL)
64
    {
65
        $fileHandle = parent::prepareForSave($pFilename);
66
 
67
        //  Default PDF paper size
68
        $paperSize = 'LETTER';    //    Letter    (8.5 in. by 11 in.)
69
 
70
        //  Check for paper size and page orientation
71
        if (is_null($this->getSheetIndex())) {
72
            $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
73
                == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
74
                    ? 'L'
75
                    : 'P';
76
            $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
77
            $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
78
        } else {
79
            $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
80
                == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
81
                    ? 'L'
82
                    : 'P';
83
            $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
84
            $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
85
        }
86
 
87
        //  Override Page Orientation
88
        if (!is_null($this->getOrientation())) {
89
            $orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)
90
                ? 'L'
91
                : 'P';
92
        }
93
        //  Override Paper Size
94
        if (!is_null($this->getPaperSize())) {
95
            $printPaperSize = $this->getPaperSize();
96
        }
97
 
98
        if (isset(self::$_paperSizes[$printPaperSize])) {
99
            $paperSize = self::$_paperSizes[$printPaperSize];
100
        }
101
 
102
 
103
        //  Create PDF
104
        $pdf = new TCPDF($orientation, 'pt', $paperSize);
105
        $pdf->setFontSubsetting(FALSE);
106
        //    Set margins, converting inches to points (using 72 dpi)
107
        $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
108
        $pdf->SetAutoPageBreak(TRUE, $printMargins->getBottom() * 72);
109
 
110
        $pdf->setPrintHeader(FALSE);
111
        $pdf->setPrintFooter(FALSE);
112
 
113
        $pdf->AddPage();
114
 
115
        //  Set the appropriate font
116
        $pdf->SetFont($this->getFont());
117
        $pdf->writeHTML(
118
            $this->generateHTMLHeader(FALSE) .
119
            $this->generateSheetData() .
120
            $this->generateHTMLFooter()
121
        );
122
 
123
        //  Document info
124
        $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
125
        $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
126
        $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
127
        $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
128
        $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
129
 
130
        //  Write to file
131
        fwrite($fileHandle, $pdf->output($pFilename, 'S'));
132
 
133
		parent::restoreStateAfterSave($fileHandle);
134
    }
135
 
136
}