PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.9.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.9.7
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 All 149 releases
visualizer / vendor / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Writer / Pdf / Tcpdf.php

Tcpdf.php in Visualizer – Tables & Charts Manager with Built-in AI Generator 3.9.7, at vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php

99 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace PhpOffice\PhpSpreadsheet\Writer\Pdf;
4
5 use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
6 use PhpOffice\PhpSpreadsheet\Writer\Pdf;
7
8 class Tcpdf extends Pdf
9 {
10 /**
11 * Gets the implementation of external PDF library that should be used.
12 *
13 * @param string $orientation Page orientation
14 * @param string $unit Unit measure
15 * @param string $paperSize Paper size
16 *
17 * @return \TCPDF implementation
18 */
19 protected function createExternalWriterInstance($orientation, $unit, $paperSize)
20 {
21 return new \TCPDF($orientation, $unit, $paperSize);
22 }
23
24 /**
25 * Save Spreadsheet to file.
26 *
27 * @param string $pFilename Name of the file to save as
28 *
29 * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
30 */
31 public function save($pFilename)
32 {
33 $fileHandle = parent::prepareForSave($pFilename);
34
35 // Default PDF paper size
36 $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
37
38 // Check for paper size and page orientation
39 if ($this->getSheetIndex() === null) {
40 $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation()
41 == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
42 $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize();
43 $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins();
44 } else {
45 $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
46 == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
47 $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
48 $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins();
49 }
50
51 // Override Page Orientation
52 if ($this->getOrientation() !== null) {
53 $orientation = ($this->getOrientation() == PageSetup::ORIENTATION_LANDSCAPE)
54 ? 'L'
55 : 'P';
56 }
57 // Override Paper Size
58 if ($this->getPaperSize() !== null) {
59 $printPaperSize = $this->getPaperSize();
60 }
61
62 if (isset(self::$paperSizes[$printPaperSize])) {
63 $paperSize = self::$paperSizes[$printPaperSize];
64 }
65
66 // Create PDF
67 $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
68 $pdf->setFontSubsetting(false);
69 // Set margins, converting inches to points (using 72 dpi)
70 $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
71 $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
72
73 $pdf->setPrintHeader(false);
74 $pdf->setPrintFooter(false);
75
76 $pdf->AddPage();
77
78 // Set the appropriate font
79 $pdf->SetFont($this->getFont());
80 $pdf->writeHTML(
81 $this->generateHTMLHeader(false) .
82 $this->generateSheetData() .
83 $this->generateHTMLFooter()
84 );
85
86 // Document info
87 $pdf->SetTitle($this->spreadsheet->getProperties()->getTitle());
88 $pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator());
89 $pdf->SetSubject($this->spreadsheet->getProperties()->getSubject());
90 $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords());
91 $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator());
92
93 // Write to file
94 fwrite($fileHandle, $pdf->output($pFilename, 'S'));
95
96 parent::restoreStateAfterSave($fileHandle);
97 }
98 }
99