1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Writer\Pdf; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\IWriter; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Pdf; |
9
|
|
|
|
10
|
|
|
class Mpdf extends Pdf implements IWriter |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Save Spreadsheet to file. |
14
|
|
|
* |
15
|
|
|
* @param string $pFilename Name of the file to save as |
16
|
|
|
* |
17
|
|
|
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception |
18
|
|
|
* @throws PhpSpreadsheetException |
19
|
|
|
*/ |
20
|
1 |
|
public function save($pFilename) |
21
|
|
|
{ |
22
|
1 |
|
$fileHandle = parent::prepareForSave($pFilename); |
|
|
|
|
23
|
|
|
|
24
|
|
|
// Default PDF paper size |
25
|
1 |
|
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
26
|
|
|
|
27
|
|
|
// Check for paper size and page orientation |
28
|
1 |
View Code Duplication |
if (null === $this->getSheetIndex()) { |
|
|
|
|
29
|
|
|
$orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation() |
30
|
|
|
== PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
31
|
|
|
$printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize(); |
32
|
|
|
} else { |
33
|
1 |
|
$orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
34
|
1 |
|
== PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
35
|
1 |
|
$printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
36
|
|
|
} |
37
|
1 |
|
$this->setOrientation($orientation); |
38
|
|
|
|
39
|
|
|
// Override Page Orientation |
40
|
1 |
|
if (null !== $this->getOrientation()) { |
41
|
1 |
|
$orientation = ($this->getOrientation() == PageSetup::ORIENTATION_DEFAULT) |
42
|
|
|
? PageSetup::ORIENTATION_PORTRAIT |
43
|
1 |
|
: $this->getOrientation(); |
44
|
|
|
} |
45
|
1 |
|
$orientation = strtoupper($orientation); |
46
|
|
|
|
47
|
|
|
// Override Paper Size |
48
|
1 |
|
if (null !== $this->getPaperSize()) { |
49
|
|
|
$printPaperSize = $this->getPaperSize(); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
if (isset(self::$paperSizes[$printPaperSize])) { |
53
|
1 |
|
$paperSize = self::$paperSizes[$printPaperSize]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// Create PDF |
57
|
1 |
|
$config = ['tempDir' => $this->tempDir]; |
58
|
1 |
|
$pdf = new \Mpdf\Mpdf($config); |
59
|
1 |
|
$ortmp = $orientation; |
60
|
1 |
|
$pdf->_setPageSize(strtoupper($paperSize), $ortmp); |
61
|
1 |
|
$pdf->DefOrientation = $orientation; |
62
|
1 |
|
$pdf->AddPage($orientation); |
63
|
|
|
|
64
|
|
|
// Document info |
65
|
1 |
|
$pdf->SetTitle($this->spreadsheet->getProperties()->getTitle()); |
66
|
1 |
|
$pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator()); |
67
|
1 |
|
$pdf->SetSubject($this->spreadsheet->getProperties()->getSubject()); |
68
|
1 |
|
$pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords()); |
69
|
1 |
|
$pdf->SetCreator($this->spreadsheet->getProperties()->getCreator()); |
70
|
|
|
|
71
|
1 |
|
$pdf->WriteHTML( |
72
|
1 |
|
$this->generateHTMLHeader(false) . |
73
|
1 |
|
$this->generateSheetData() . |
74
|
1 |
|
$this->generateHTMLFooter() |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
// Write to file |
78
|
1 |
|
fwrite($fileHandle, $pdf->Output('', 'S')); |
79
|
|
|
|
80
|
1 |
|
parent::restoreStateAfterSave($fileHandle); |
|
|
|
|
81
|
1 |
|
} |
82
|
|
|
} |
83
|
|
|
|
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.