ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Dompdf.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class Dompdf extends Pdf
9 {
15  protected function createExternalWriterInstance()
16  {
17  return new \Dompdf\Dompdf();
18  }
19 
25  public function save($pFilename): void
26  {
27  $fileHandle = parent::prepareForSave($pFilename);
28 
29  // Default PDF paper size
30  $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
31 
32  // Check for paper size and page orientation
33  if ($this->getSheetIndex() === null) {
34  $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation()
35  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
36  $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize();
37  } else {
38  $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
39  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
40  $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
41  }
42 
43  $orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
44 
45  // Override Page Orientation
46  if ($this->getOrientation() !== null) {
49  : $this->getOrientation();
50  }
51  // Override Paper Size
52  if ($this->getPaperSize() !== null) {
53  $printPaperSize = $this->getPaperSize();
54  }
55 
56  if (isset(self::$paperSizes[$printPaperSize])) {
57  $paperSize = self::$paperSizes[$printPaperSize];
58  }
59 
60  // Create PDF
62  $pdf->setPaper($paperSize, $orientation);
63 
64  $pdf->loadHtml($this->generateHTMLAll());
65  $pdf->render();
66 
67  // Write to file
68  fwrite($fileHandle, $pdf->output());
69 
70  parent::restoreStateAfterSave();
71  }
72 }
$pdf
Definition: example_001.php:31
getSheetIndex()
Get sheet index.
Definition: Html.php:294
getPaperSize()
Get Paper Size.
Definition: Pdf.php:160
getOrientation()
Get Orientation.
Definition: Pdf.php:184
createExternalWriterInstance()
Gets the implementation of external PDF library that should be used.
Definition: Dompdf.php:15
save($pFilename)
Save Spreadsheet to file.
Definition: Dompdf.php:25