PluginProbe
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin / 6.5.1.7
wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin v6.5.1.7
6.5.1.7 6.5.1.6 6.5.1.5 6.5.1.4 6.5.1.3 6.5.1.2 6.5.1.1 6.5.0.9 6.5.0.8 6.5.0.7 6.5.0.6 trunk 3.4.2.40 3.4.2.41 3.4.2.42 3.4.2.43 3.4.2.44 3.4.2.45 3.4.2.46 3.4.2.47 3.4.2.48 3.4.2.49 3.4.2.50 6.3.2 6.3.3.1 All 47 releases
wpdatatables / lib / phpoffice / phpspreadsheet / src / PhpSpreadsheet / Writer / Pdf / Tcpdf.php

Tcpdf.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Pdf/Tcpdf.php

85 lines 3.0 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\Spreadsheet;
6 use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
7 use PhpOffice\PhpSpreadsheet\Writer\Pdf;
8
9 class Tcpdf extends Pdf
10 {
11 /**
12 * Create a new PDF Writer instance.
13 *
14 * @param Spreadsheet $spreadsheet Spreadsheet object
15 */
16 public function __construct(Spreadsheet $spreadsheet)
17 {
18 parent::__construct($spreadsheet);
19 $this->setUseInlineCss(true);
20 }
21
22 /**
23 * Gets the implementation of external PDF library that should be used.
24 *
25 * @param string $orientation Page orientation
26 * @param string $unit Unit measure
27 * @param array|string $paperSize Paper size
28 *
29 * @return \TCPDF implementation
30 */
31 protected function createExternalWriterInstance($orientation, $unit, $paperSize)
32 {
33 return new \TCPDF($orientation, $unit, $paperSize);
34 }
35
36 /**
37 * Save Spreadsheet to file.
38 *
39 * @param string $filename Name of the file to save as
40 */
41 public function save($filename, int $flags = 0): void
42 {
43 $fileHandle = parent::prepareForSave($filename);
44
45 // Default PDF paper size
46 $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
47
48 // Check for paper size and page orientation
49 $setup = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageSetup();
50 $orientation = $this->getOrientation() ?? $setup->getOrientation();
51 $orientation = ($orientation === PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
52 $printPaperSize = $this->getPaperSize() ?? $setup->getPaperSize();
53 $paperSize = self::$paperSizes[$printPaperSize] ?? PageSetup::getPaperSizeDefault();
54 $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex() ?? 0)->getPageMargins();
55
56 // Create PDF
57 $pdf = $this->createExternalWriterInstance($orientation, 'pt', $paperSize);
58 $pdf->setFontSubsetting(false);
59 // Set margins, converting inches to points (using 72 dpi)
60 $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
61 $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
62
63 $pdf->setPrintHeader(false);
64 $pdf->setPrintFooter(false);
65
66 $pdf->AddPage();
67
68 // Set the appropriate font
69 $pdf->SetFont($this->getFont());
70 $pdf->writeHTML($this->generateHTMLAll());
71
72 // Document info
73 $pdf->SetTitle($this->spreadsheet->getProperties()->getTitle());
74 $pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator());
75 $pdf->SetSubject($this->spreadsheet->getProperties()->getSubject());
76 $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords());
77 $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator());
78
79 // Write to file
80 fwrite($fileHandle, $pdf->output('', 'S'));
81
82 parent::restoreStateAfterSave();
83 }
84 }
85