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 TcPDF 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
|
1 |
|
public function save($pFilename = null) |
37
|
|
|
{ |
38
|
1 |
|
$fileHandle = parent::prepareForSave($pFilename); |
|
|
|
|
39
|
|
|
|
40
|
|
|
// Default PDF paper size |
41
|
1 |
|
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
42
|
|
|
|
43
|
|
|
// Check for paper size and page orientation |
44
|
1 |
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
|
1 |
|
$orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
51
|
1 |
|
== \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
52
|
1 |
|
$printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
53
|
1 |
|
$printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Override Page Orientation |
57
|
1 |
|
if (!is_null($this->getOrientation())) { |
58
|
|
|
$orientation = ($this->getOrientation() == \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) |
59
|
|
|
? 'L' |
60
|
|
|
: 'P'; |
61
|
|
|
} |
62
|
|
|
// Override Paper Size |
63
|
1 |
|
if (!is_null($this->getPaperSize())) { |
64
|
|
|
$printPaperSize = $this->getPaperSize(); |
65
|
|
|
} |
66
|
|
|
|
67
|
1 |
|
if (isset(self::$paperSizes[$printPaperSize])) { |
68
|
1 |
|
$paperSize = self::$paperSizes[$printPaperSize]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Create PDF |
72
|
1 |
|
$pdf = new \TCPDF($orientation, 'pt', $paperSize); |
73
|
1 |
|
$pdf->setFontSubsetting(false); |
74
|
|
|
// Set margins, converting inches to points (using 72 dpi) |
75
|
1 |
|
$pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72); |
76
|
1 |
|
$pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72); |
77
|
|
|
|
78
|
1 |
|
$pdf->setPrintHeader(false); |
79
|
1 |
|
$pdf->setPrintFooter(false); |
80
|
|
|
|
81
|
1 |
|
$pdf->AddPage(); |
82
|
|
|
|
83
|
|
|
// Set the appropriate font |
84
|
1 |
|
$pdf->SetFont($this->getFont()); |
85
|
1 |
|
$pdf->writeHTML( |
86
|
1 |
|
$this->generateHTMLHeader(false) . |
87
|
1 |
|
$this->generateSheetData() . |
88
|
1 |
|
$this->generateHTMLFooter() |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
// Document info |
92
|
1 |
|
$pdf->SetTitle($this->spreadsheet->getProperties()->getTitle()); |
93
|
1 |
|
$pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator()); |
94
|
1 |
|
$pdf->SetSubject($this->spreadsheet->getProperties()->getSubject()); |
95
|
1 |
|
$pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); |
96
|
1 |
|
$pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); |
97
|
|
|
|
98
|
|
|
// Write to file |
99
|
1 |
|
fwrite($fileHandle, $pdf->output($pFilename, 'S')); |
100
|
|
|
|
101
|
1 |
|
parent::restoreStateAfterSave($fileHandle); |
|
|
|
|
102
|
1 |
|
} |
103
|
|
|
} |
104
|
|
|
|
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.