1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2015 PhpSpreadsheet. |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* |
24
|
|
|
* @copyright Copyright (c) 2006 - 2015 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
25
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
26
|
|
|
*/ |
27
|
|
|
class MPDF extends Core implements \PhpOffice\PhpSpreadsheet\Writer\IWriter |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Save Spreadsheet to file. |
31
|
|
|
* |
32
|
|
|
* @param string $pFilename Name of the file to save as |
33
|
|
|
* |
34
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception |
35
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Exception |
36
|
|
|
*/ |
37
|
1 |
|
public function save($pFilename = null) |
38
|
|
|
{ |
39
|
1 |
|
$fileHandle = parent::prepareForSave($pFilename); |
|
|
|
|
40
|
|
|
|
41
|
|
|
// Default PDF paper size |
42
|
1 |
|
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
43
|
|
|
|
44
|
|
|
// Check for paper size and page orientation |
45
|
1 |
View Code Duplication |
if (null === $this->getSheetIndex()) { |
|
|
|
|
46
|
|
|
$orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() |
47
|
|
|
== \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
48
|
|
|
$printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); |
49
|
|
|
$printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); |
|
|
|
|
50
|
|
|
} else { |
51
|
1 |
|
$orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
52
|
1 |
|
== \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
53
|
1 |
|
$printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
54
|
1 |
|
$printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); |
|
|
|
|
55
|
|
|
} |
56
|
1 |
|
$this->setOrientation($orientation); |
57
|
|
|
|
58
|
|
|
// Override Page Orientation |
59
|
1 |
View Code Duplication |
if (null !== $this->getOrientation()) { |
|
|
|
|
60
|
1 |
|
$orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_DEFAULT) |
61
|
|
|
? \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT |
62
|
1 |
|
: $this->getOrientation(); |
63
|
|
|
} |
64
|
1 |
|
$orientation = strtoupper($orientation); |
65
|
|
|
|
66
|
|
|
// Override Paper Size |
67
|
1 |
|
if (null !== $this->getPaperSize()) { |
68
|
|
|
$printPaperSize = $this->getPaperSize(); |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
if (isset(self::$paperSizes[$printPaperSize])) { |
72
|
1 |
|
$paperSize = self::$paperSizes[$printPaperSize]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Create PDF |
76
|
1 |
|
$pdf = new \mPDF(); |
77
|
1 |
|
$ortmp = $orientation; |
78
|
1 |
|
$pdf->_setPageSize(strtoupper($paperSize), $ortmp); |
79
|
1 |
|
$pdf->DefOrientation = $orientation; |
80
|
1 |
|
$pdf->AddPage($orientation); |
81
|
|
|
|
82
|
|
|
// Document info |
83
|
1 |
|
$pdf->SetTitle($this->spreadsheet->getProperties()->getTitle()); |
84
|
1 |
|
$pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator()); |
85
|
1 |
|
$pdf->SetSubject($this->spreadsheet->getProperties()->getSubject()); |
86
|
1 |
|
$pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); |
87
|
1 |
|
$pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); |
88
|
|
|
|
89
|
1 |
|
$pdf->WriteHTML( |
90
|
1 |
|
$this->generateHTMLHeader(false) . |
91
|
1 |
|
$this->generateSheetData() . |
92
|
1 |
|
$this->generateHTMLFooter() |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
// Write to file |
96
|
1 |
|
fwrite($fileHandle, $pdf->Output('', 'S')); |
97
|
|
|
|
98
|
1 |
|
parent::restoreStateAfterSave($fileHandle); |
|
|
|
|
99
|
1 |
|
} |
100
|
|
|
} |
101
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.