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 DomPDF 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
|
|
|
*/ |
36
|
2 |
|
public function save($pFilename = null) |
37
|
|
|
{ |
38
|
2 |
|
$fileHandle = parent::prepareForSave($pFilename); |
|
|
|
|
39
|
|
|
|
40
|
|
|
// Default PDF paper size |
41
|
2 |
|
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
42
|
|
|
|
43
|
|
|
// Check for paper size and page orientation |
44
|
2 |
View Code Duplication |
if (is_null($this->getSheetIndex())) { |
|
|
|
|
45
|
|
|
$orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() |
46
|
|
|
== \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
47
|
|
|
$printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); |
48
|
|
|
$printMargins = $this->spreadsheet->getSheet(0)->getPageMargins(); |
|
|
|
|
49
|
|
|
} else { |
50
|
2 |
|
$orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
51
|
2 |
|
== \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
52
|
2 |
|
$printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
53
|
2 |
|
$printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
2 |
|
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait'; |
57
|
|
|
|
58
|
|
|
// Override Page Orientation |
59
|
2 |
View Code Duplication |
if (!is_null($this->getOrientation())) { |
|
|
|
|
60
|
|
|
$orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_DEFAULT) |
61
|
|
|
? \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT |
62
|
|
|
: $this->getOrientation(); |
63
|
|
|
} |
64
|
|
|
// Override Paper Size |
65
|
2 |
|
if (!is_null($this->getPaperSize())) { |
66
|
|
|
$printPaperSize = $this->getPaperSize(); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
if (isset(self::$paperSizes[$printPaperSize])) { |
70
|
2 |
|
$paperSize = self::$paperSizes[$printPaperSize]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Create PDF |
74
|
2 |
|
$pdf = new \Dompdf\Dompdf(); |
75
|
2 |
|
$pdf->set_paper(strtolower($paperSize), $orientation); |
|
|
|
|
76
|
|
|
|
77
|
2 |
|
$pdf->load_html( |
|
|
|
|
78
|
2 |
|
$this->generateHTMLHeader(false) . |
79
|
2 |
|
$this->generateSheetData() . |
80
|
2 |
|
$this->generateHTMLFooter() |
81
|
|
|
); |
82
|
2 |
|
$pdf->render(); |
83
|
|
|
|
84
|
|
|
// Write to file |
85
|
2 |
|
fwrite($fileHandle, $pdf->output()); |
86
|
|
|
|
87
|
2 |
|
parent::restoreStateAfterSave($fileHandle); |
|
|
|
|
88
|
2 |
|
} |
89
|
|
|
} |
90
|
|
|
|
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.