ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Mpdf.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class Mpdf extends Pdf
9 {
18  {
19  return new \Mpdf\Mpdf($config);
20  }
21 
27  public function save($pFilename): void
28  {
29  $fileHandle = parent::prepareForSave($pFilename);
30 
31  // Default PDF paper size
32  $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
33 
34  // Check for paper size and page orientation
35  if (null === $this->getSheetIndex()) {
36  $orientation = ($this->spreadsheet->getSheet(0)->getPageSetup()->getOrientation()
37  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
38  $printPaperSize = $this->spreadsheet->getSheet(0)->getPageSetup()->getPaperSize();
39  } else {
40  $orientation = ($this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
41  == PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P';
42  $printPaperSize = $this->spreadsheet->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
43  }
45 
46  // Override Page Orientation
47  if (null !== $this->getOrientation()) {
50  : $this->getOrientation();
51  }
52  $orientation = strtoupper($orientation);
53 
54  // Override Paper Size
55  if (null !== $this->getPaperSize()) {
56  $printPaperSize = $this->getPaperSize();
57  }
58 
59  if (isset(self::$paperSizes[$printPaperSize])) {
60  $paperSize = self::$paperSizes[$printPaperSize];
61  }
62 
63  // Create PDF
64  $config = ['tempDir' => $this->tempDir . '/mpdf'];
66  $ortmp = $orientation;
67  $pdf->_setPageSize($paperSize, $ortmp);
68  $pdf->DefOrientation = $orientation;
69  $pdf->AddPageByArray([
70  'orientation' => $orientation,
71  'margin-left' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getLeft()),
72  'margin-right' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getRight()),
73  'margin-top' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getTop()),
74  'margin-bottom' => $this->inchesToMm($this->spreadsheet->getActiveSheet()->getPageMargins()->getBottom()),
75  ]);
76 
77  // Document info
78  $pdf->SetTitle($this->spreadsheet->getProperties()->getTitle());
79  $pdf->SetAuthor($this->spreadsheet->getProperties()->getCreator());
80  $pdf->SetSubject($this->spreadsheet->getProperties()->getSubject());
81  $pdf->SetKeywords($this->spreadsheet->getProperties()->getKeywords());
82  $pdf->SetCreator($this->spreadsheet->getProperties()->getCreator());
83 
84  $html = $this->generateHTMLAll();
85  foreach (\array_chunk(\explode(PHP_EOL, $html), 1000) as $lines) {
86  $pdf->WriteHTML(\implode(PHP_EOL, $lines));
87  }
88 
89  // Write to file
90  fwrite($fileHandle, $pdf->Output('', 'S'));
91 
92  parent::restoreStateAfterSave();
93  }
94 
102  private function inchesToMm($inches)
103  {
104  return $inches * 25.4;
105  }
106 }
setOrientation($pValue)
Set Orientation.
Definition: Pdf.php:196
$config
Definition: bootstrap.php:15
$pdf
Definition: example_001.php:31
save($pFilename)
Save Spreadsheet to file.
Definition: Mpdf.php:27
PHP_EOL
Definition: complexTest.php:5
getSheetIndex()
Get sheet index.
Definition: Html.php:294
getPaperSize()
Get Paper Size.
Definition: Pdf.php:160
createExternalWriterInstance($config)
Gets the implementation of external PDF library that should be used.
Definition: Mpdf.php:17
getOrientation()
Get Orientation.
Definition: Pdf.php:184
inchesToMm($inches)
Convert inches to mm.
Definition: Mpdf.php:102
$html
Definition: example_001.php:87