ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Tcpdf.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class Tcpdf extends Pdf
10 {
17  {
18  parent::__construct($spreadsheet);
19  $this->setUseInlineCss(true);
20  }
21 
32  {
33  return new \TCPDF($orientation, $unit, $paperSize);
34  }
35 
41  public function save($pFilename): void
42  {
43  $fileHandle = parent::prepareForSave($pFilename);
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  if ($this->getSheetIndex() === null) {
50  $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation()
51  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
52  $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize();
53  $printMargins = $this->spreadsheet->getSheet(0)->getPageMargins();
54  } else {
55  $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
56  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
57  $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
58  $printMargins = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageMargins();
59  }
60 
61  // Override Page Orientation
62  if ($this->getOrientation() !== null) {
64  ? 'L'
65  : 'P';
66  }
67  // Override Paper Size
68  if ($this->getPaperSize() !== null) {
69  $printPaperSize = $this->getPaperSize();
70  }
71 
72  if (isset(self::$paperSizes[$printPaperSize])) {
73  $paperSize = self::$paperSizes[$printPaperSize];
74  }
75 
76  // Create PDF
78  $pdf->setFontSubsetting(false);
79  // Set margins, converting inches to points (using 72 dpi)
80  $pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72);
81  $pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72);
82 
83  $pdf->setPrintHeader(false);
84  $pdf->setPrintFooter(false);
85 
86  $pdf->AddPage();
87 
88  // Set the appropriate font
89  $pdf->SetFont($this->getFont());
90  $pdf->writeHTML($this->generateHTMLAll());
91 
92  // Document info
93  $pdf->SetTitle($this->spreadsheet->getProperties()->getTitle());
94  $pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator());
95  $pdf->SetSubject($this->spreadsheet->getProperties()->getSubject());
96  $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords());
97  $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator());
98 
99  // Write to file
100  fwrite($fileHandle, $pdf->output($pFilename, 'S'));
101 
102  parent::restoreStateAfterSave();
103  }
104 }
save($pFilename)
Save Spreadsheet to file.
Definition: Tcpdf.php:41
$pdf
Definition: example_001.php:31
__construct(Spreadsheet $spreadsheet)
Create a new PDF Writer instance.
Definition: Tcpdf.php:16
getSheetIndex()
Get sheet index.
Definition: Html.php:294
getPaperSize()
Get Paper Size.
Definition: Pdf.php:160
getOrientation()
Get Orientation.
Definition: Pdf.php:184
createExternalWriterInstance($orientation, $unit, $paperSize)
Gets the implementation of external PDF library that should be used.
Definition: Tcpdf.php:31
setUseInlineCss($pValue)
Set use inline CSS?
Definition: Html.php:1612