Subversion Repositories eFlore/Applications.cel

Rev

Rev 2388 | Details | Compare with Previous | 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
/**
30
 *  PHPExcel_Writer_PDF_Core
31
 *
32
 *  @category    PHPExcel
33
 *  @package     PHPExcel_Writer_PDF
34
 *  @copyright   Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
35
 */
36
abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML
37
{
38
    /**
39
     * Temporary storage directory
40
     *
41
     * @var string
42
     */
43
    protected $_tempDir = '';
44
 
45
    /**
46
     * Font
47
     *
48
     * @var string
49
     */
50
    protected $_font = 'freesans';
51
 
52
    /**
53
     * Orientation (Over-ride)
54
     *
55
     * @var string
56
     */
57
    protected $_orientation    = NULL;
58
 
59
    /**
60
     * Paper size (Over-ride)
61
     *
62
     * @var int
63
     */
64
    protected $_paperSize    = NULL;
65
 
66
 
67
    /**
68
     * Temporary storage for Save Array Return type
69
     *
70
     * @var string
71
     */
72
	private $_saveArrayReturnType;
73
 
74
    /**
75
     * Paper Sizes xRef List
76
     *
77
     * @var array
78
     */
79
    protected static $_paperSizes = array(
80
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER
81
            => 'LETTER',                 //    (8.5 in. by 11 in.)
82
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_SMALL
83
            => 'LETTER',                 //    (8.5 in. by 11 in.)
84
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID
85
            => array(792.00, 1224.00),   //    (11 in. by 17 in.)
86
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEDGER
87
            => array(1224.00, 792.00),   //    (17 in. by 11 in.)
88
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL
89
            => 'LEGAL',                  //    (8.5 in. by 14 in.)
90
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STATEMENT
91
            => array(396.00, 612.00),    //    (5.5 in. by 8.5 in.)
92
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_EXECUTIVE
93
            => 'EXECUTIVE',              //    (7.25 in. by 10.5 in.)
94
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3
95
            => 'A3',                     //    (297 mm by 420 mm)
96
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4
97
            => 'A4',                     //    (210 mm by 297 mm)
98
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_SMALL
99
            => 'A4',                     //    (210 mm by 297 mm)
100
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5
101
            => 'A5',                     //    (148 mm by 210 mm)
102
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4
103
            => 'B4',                     //    (250 mm by 353 mm)
104
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5
105
            => 'B5',                     //    (176 mm by 250 mm)
106
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_FOLIO
107
            => 'FOLIO',                  //    (8.5 in. by 13 in.)
108
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_QUARTO
109
            => array(609.45, 779.53),    //    (215 mm by 275 mm)
110
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_1
111
            => array(720.00, 1008.00),   //    (10 in. by 14 in.)
112
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_2
113
            => array(792.00, 1224.00),   //    (11 in. by 17 in.)
114
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NOTE
115
            => 'LETTER',                 //    (8.5 in. by 11 in.)
116
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO9_ENVELOPE
117
            => array(279.00, 639.00),    //    (3.875 in. by 8.875 in.)
118
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO10_ENVELOPE
119
            => array(297.00, 684.00),    //    (4.125 in. by 9.5 in.)
120
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO11_ENVELOPE
121
            => array(324.00, 747.00),    //    (4.5 in. by 10.375 in.)
122
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO12_ENVELOPE
123
            => array(342.00, 792.00),    //    (4.75 in. by 11 in.)
124
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO14_ENVELOPE
125
            => array(360.00, 828.00),    //    (5 in. by 11.5 in.)
126
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C
127
            => array(1224.00, 1584.00),  //    (17 in. by 22 in.)
128
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_D
129
            => array(1584.00, 2448.00),  //    (22 in. by 34 in.)
130
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_E
131
            => array(2448.00, 3168.00),  //    (34 in. by 44 in.)
132
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_DL_ENVELOPE
133
            => array(311.81, 623.62),    //    (110 mm by 220 mm)
134
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C5_ENVELOPE
135
            => 'C5',                     //    (162 mm by 229 mm)
136
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C3_ENVELOPE
137
            => 'C3',                     //    (324 mm by 458 mm)
138
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C4_ENVELOPE
139
            => 'C4',                     //    (229 mm by 324 mm)
140
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C6_ENVELOPE
141
            => 'C6',                     //    (114 mm by 162 mm)
142
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_C65_ENVELOPE
143
            => array(323.15, 649.13),    //    (114 mm by 229 mm)
144
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4_ENVELOPE
145
            => 'B4',                     //    (250 mm by 353 mm)
146
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5_ENVELOPE
147
            => 'B5',                     //    (176 mm by 250 mm)
148
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_B6_ENVELOPE
149
            => array(498.90, 354.33),    //    (176 mm by 125 mm)
150
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_ITALY_ENVELOPE
151
            => array(311.81, 651.97),    //    (110 mm by 230 mm)
152
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_MONARCH_ENVELOPE
153
            => array(279.00, 540.00),    //    (3.875 in. by 7.5 in.)
154
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_6_3_4_ENVELOPE
155
            => array(261.00, 468.00),    //    (3.625 in. by 6.5 in.)
156
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_US_STANDARD_FANFOLD
157
            => array(1071.00, 792.00),   //    (14.875 in. by 11 in.)
158
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD
159
            => array(612.00, 864.00),    //    (8.5 in. by 12 in.)
160
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD
161
            => 'FOLIO',                  //    (8.5 in. by 13 in.)
162
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B4
163
            => 'B4',                     //    (250 mm by 353 mm)
164
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD
165
            => array(566.93, 419.53),    //    (200 mm by 148 mm)
166
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_1
167
            => array(648.00, 792.00),    //    (9 in. by 11 in.)
168
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_2
169
            => array(720.00, 792.00),    //    (10 in. by 11 in.)
170
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_3
171
            => array(1080.00, 792.00),   //    (15 in. by 11 in.)
172
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_INVITE_ENVELOPE
173
            => array(623.62, 623.62),    //    (220 mm by 220 mm)
174
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER
175
            => array(667.80, 864.00),    //    (9.275 in. by 12 in.)
176
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER
177
            => array(667.80, 1080.00),   //    (9.275 in. by 15 in.)
178
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER
179
            => array(841.68, 1296.00),   //    (11.69 in. by 18 in.)
180
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_EXTRA_PAPER
181
            => array(668.98, 912.76),    //    (236 mm by 322 mm)
182
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER
183
            => array(595.80, 792.00),    //    (8.275 in. by 11 in.)
184
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER
185
            => 'A4',                     //    (210 mm by 297 mm)
186
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER
187
            => array(667.80, 864.00),    //    (9.275 in. by 12 in.)
188
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER
189
            => array(643.46, 1009.13),   //    (227 mm by 356 mm)
190
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER
191
            => array(864.57, 1380.47),   //    (305 mm by 487 mm)
192
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_PLUS_PAPER
193
            => array(612.00, 913.68),    //    (8.5 in. by 12.69 in.)
194
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_PLUS_PAPER
195
            => array(595.28, 935.43),    //    (210 mm by 330 mm)
196
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER
197
            => 'A5',                     //    (148 mm by 210 mm)
198
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER
199
            => array(515.91, 728.50),    //    (182 mm by 257 mm)
200
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_PAPER
201
            => array(912.76, 1261.42),   //    (322 mm by 445 mm)
202
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_EXTRA_PAPER
203
            => array(493.23, 666.14),    //    (174 mm by 235 mm)
204
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER
205
            => array(569.76, 782.36),    //    (201 mm by 276 mm)
206
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER
207
            => 'A2',                     //    (420 mm by 594 mm)
208
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER
209
            => 'A3',                     //    (297 mm by 420 mm)
210
        PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER
211
            => array(912.76, 1261.42)    //    (322 mm by 445 mm)
212
    );
213
 
214
    /**
215
     *  Create a new PHPExcel_Writer_PDF
216
     *
217
     *  @param     PHPExcel    $phpExcel    PHPExcel object
218
     */
219
    public function __construct(PHPExcel $phpExcel)
220
    {
221
        parent::__construct($phpExcel);
222
        $this->setUseInlineCss(TRUE);
223
        $this->_tempDir = PHPExcel_Shared_File::sys_get_temp_dir();
224
    }
225
 
226
    /**
227
     *  Get Font
228
     *
229
     *  @return string
230
     */
231
    public function getFont()
232
    {
233
        return $this->_font;
234
    }
235
 
236
    /**
237
     *  Set font. Examples:
238
     *      'arialunicid0-chinese-simplified'
239
     *      'arialunicid0-chinese-traditional'
240
     *      'arialunicid0-korean'
241
     *      'arialunicid0-japanese'
242
     *
243
     *  @param    string    $fontName
244
     */
245
    public function setFont($fontName)
246
    {
247
        $this->_font = $fontName;
248
        return $this;
249
    }
250
 
251
    /**
252
     *  Get Paper Size
253
     *
254
     *  @return int
255
     */
256
    public function getPaperSize()
257
    {
258
        return $this->_paperSize;
259
    }
260
 
261
    /**
262
     *  Set Paper Size
263
     *
264
     *  @param  string  $pValue Paper size
265
     *  @return PHPExcel_Writer_PDF
266
     */
267
    public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER)
268
    {
269
        $this->_paperSize = $pValue;
270
        return $this;
271
    }
272
 
273
    /**
274
     *  Get Orientation
275
     *
276
     *  @return string
277
     */
278
    public function getOrientation()
279
    {
280
        return $this->_orientation;
281
    }
282
 
283
    /**
284
     *  Set Orientation
285
     *
286
     *  @param string $pValue  Page orientation
287
     *  @return PHPExcel_Writer_PDF
288
     */
289
    public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT)
290
    {
291
        $this->_orientation = $pValue;
292
        return $this;
293
    }
294
 
295
    /**
296
     *  Get temporary storage directory
297
     *
298
     *  @return string
299
     */
300
    public function getTempDir()
301
    {
302
        return $this->_tempDir;
303
    }
304
 
305
    /**
306
     *  Set temporary storage directory
307
     *
308
     *  @param     string        $pValue        Temporary storage directory
309
     *  @throws    PHPExcel_Writer_Exception    when directory does not exist
310
     *  @return    PHPExcel_Writer_PDF
311
     */
312
    public function setTempDir($pValue = '')
313
    {
314
        if (is_dir($pValue)) {
315
            $this->_tempDir = $pValue;
316
        } else {
317
            throw new PHPExcel_Writer_Exception("Directory does not exist: $pValue");
318
        }
319
        return $this;
320
    }
321
 
322
    /**
323
     *  Save PHPExcel to PDF file, pre-save
324
     *
325
     *  @param     string     $pFilename   Name of the file to save as
326
     *  @throws    PHPExcel_Writer_Exception
327
     */
328
    protected function prepareForSave($pFilename = NULL)
329
    {
330
        //  garbage collect
331
        $this->_phpExcel->garbageCollect();
332
 
333
        $this->_saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
334
        PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);
335
 
336
        //  Open file
337
        $fileHandle = fopen($pFilename, 'w');
338
        if ($fileHandle === FALSE) {
339
            throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing.");
340
        }
341
 
342
        //  Set PDF
343
        $this->_isPdf = TRUE;
344
        //  Build CSS
345
        $this->buildCSS(TRUE);
346
 
347
        return $fileHandle;
348
    }
349
 
350
    /**
351
     *  Save PHPExcel to PDF file, post-save
352
     *
353
     *  @param     resource      $fileHandle
354
     *  @throws    PHPExcel_Writer_Exception
355
     */
356
    protected function restoreStateAfterSave($fileHandle)
357
    {
358
        //  Close file
359
        fclose($fileHandle);
360
 
361
        PHPExcel_Calculation::setArrayReturnType($this->_saveArrayReturnType);
362
    }
363
 
364
}