ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
DomPDF.php
Go to the documentation of this file.
1 <?php
31 if (file_exists($pdfRendererClassFile)) {
32  require_once $pdfRendererClassFile;
33 } else {
34  throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library');
35 }
36 
45 {
51  public function __construct(PHPExcel $phpExcel)
52  {
53  parent::__construct($phpExcel);
54  }
55 
62  public function save($pFilename = NULL)
63  {
64  $fileHandle = parent::prepareForSave($pFilename);
65 
66  // Default PDF paper size
67  $paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.)
68 
69  // Check for paper size and page orientation
70  if (is_null($this->getSheetIndex())) {
71  $orientation = ($this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation()
73  ? 'L'
74  : 'P';
75  $printPaperSize = $this->_phpExcel->getSheet(0)->getPageSetup()->getPaperSize();
76  $printMargins = $this->_phpExcel->getSheet(0)->getPageMargins();
77  } else {
78  $orientation = ($this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation()
80  ? 'L'
81  : 'P';
82  $printPaperSize = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize();
83  $printMargins = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageMargins();
84  }
85 
86 
87  $orientation = ($orientation == 'L') ? 'landscape' : 'portrait';
88 
89  // Override Page Orientation
90  if (!is_null($this->getOrientation())) {
93  : $this->getOrientation();
94  }
95  // Override Paper Size
96  if (!is_null($this->getPaperSize())) {
97  $printPaperSize = $this->getPaperSize();
98  }
99 
100  if (isset(self::$_paperSizes[$printPaperSize])) {
101  $paperSize = self::$_paperSizes[$printPaperSize];
102  }
103 
104 
105  // Create PDF
106  $pdf = new DOMPDF();
107  $pdf->set_paper(strtolower($paperSize), $orientation);
108 
109  $pdf->load_html(
110  $this->generateHTMLHeader(FALSE) .
111  $this->generateSheetData() .
112  $this->generateHTMLFooter()
113  );
114  $pdf->render();
115 
116  // Write to file
117  fwrite($fileHandle, $pdf->output());
118 
119  parent::restoreStateAfterSave($fileHandle);
120  }
121 
122 }
static getPdfRendererPath()
Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use...
Definition: Settings.php:354
getOrientation()
Get Orientation.
Definition: Core.php:278
$pdf
Definition: example_001.php:31
generateHTMLHeader($pIncludeStyles=false)
Generate HTML header.
Definition: HTML.php:305
getSheetIndex()
Get sheet index.
Definition: HTML.php:255
getPaperSize()
Get Paper Size.
Definition: Core.php:256
save($pFilename=NULL)
Save PHPExcel to file.
Definition: DomPDF.php:62
__construct(PHPExcel $phpExcel)
Create a new PHPExcel_Writer_PDF.
Definition: DomPDF.php:51
generateSheetData()
Generate sheet data.
Definition: HTML.php:356
$pdfRendererClassFile
Require DomPDF library.
Definition: DomPDF.php:30
generateHTMLFooter()
Generate HTML footer.
Definition: HTML.php:1004