1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Copyright (c) 2006 - 2015 PhpSpreadsheet. |
9
|
|
|
* |
10
|
|
|
* This library is free software; you can redistribute it and/or |
11
|
|
|
* modify it under the terms of the GNU Lesser General Public |
12
|
|
|
* License as published by the Free Software Foundation; either |
13
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
14
|
|
|
* |
15
|
|
|
* This library is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
18
|
|
|
* Lesser General Public License for more details. |
19
|
|
|
* |
20
|
|
|
* You should have received a copy of the GNU Lesser General Public |
21
|
|
|
* License along with this library; if not, write to the Free Software |
22
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23
|
|
|
* |
24
|
|
|
* @category PhpSpreadsheet |
25
|
|
|
* |
26
|
|
|
* @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
27
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
28
|
|
|
*/ |
29
|
|
|
class Pdf implements IWriter |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The wrapper for the requested PDF rendering engine. |
33
|
|
|
* |
34
|
|
|
* @var PDF\Core |
35
|
|
|
*/ |
36
|
|
|
private $renderer = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Instantiate a new renderer of the configured type within this container class. |
40
|
|
|
* |
41
|
|
|
* @param \PhpOffice\PhpSpreadsheet\Spreadsheet $spreadsheet PhpSpreadsheet object |
42
|
|
|
* |
43
|
|
|
* @throws Exception when PDF library is not configured |
44
|
|
|
*/ |
45
|
4 |
|
public function __construct(Spreadsheet $spreadsheet) |
46
|
|
|
{ |
47
|
4 |
|
$pdfLibraryName = \PhpOffice\PhpSpreadsheet\Settings::getPdfRendererName(); |
48
|
4 |
|
if (is_null($pdfLibraryName)) { |
49
|
|
|
throw new Exception('PDF Rendering library has not been defined.'); |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
$rendererName = '\\PhpOffice\\PhpSpreadsheet\\Writer\\Pdf\\' . $pdfLibraryName; |
53
|
4 |
|
$this->renderer = new $rendererName($spreadsheet); |
54
|
4 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Magic method to handle direct calls to the configured PDF renderer wrapper class. |
58
|
|
|
* |
59
|
|
|
* @param string $name Renderer library method name |
60
|
|
|
* @param mixed[] $arguments Array of arguments to pass to the renderer method |
61
|
|
|
* |
62
|
|
|
* @return mixed Returned data from the PDF renderer wrapper method |
63
|
|
|
*/ |
64
|
|
|
public function __call($name, $arguments) |
65
|
|
|
{ |
66
|
|
|
if ($this->renderer === null) { |
67
|
|
|
throw new Exception('PDF Rendering library has not been defined.'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return call_user_func_array([$this->renderer, $name], $arguments); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* {@inheritdoc} |
75
|
|
|
*/ |
76
|
4 |
|
public function save($pFilename = null) |
77
|
|
|
{ |
78
|
4 |
|
$this->renderer->save($pFilename); |
79
|
4 |
|
} |
80
|
|
|
} |
81
|
|
|
|