ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
PDF.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/IWriter.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/Writer/HTML.php';
42 
44 require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
45 
47 require_once PHPEXCEL_ROOT . 'PHPExcel/RichText.php';
48 
50 require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Drawing.php';
51 
53 require_once PHPEXCEL_ROOT . 'PHPExcel/HashTable.php';
54 
56 require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PDF.php';
57 
58 
72  private $_tempDir = '';
73 
79  public function __construct(PHPExcel $phpExcel) {
80  parent::__construct($phpExcel);
81  $this->setUseInlineCss(true);
82  $this->_tempDir = sys_get_temp_dir();
83  }
84 
91  public function save($pFilename = null) {
92  // garbage collect
93  $this->_phpExcel->garbageCollect();
94 
95  $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
97 
98  // Open file
99  $fileHandle = fopen($pFilename, 'w');
100  if ($fileHandle === false) {
101  throw new Exception("Could not open file $pFilename for writing.");
102  }
103 
104  // Set PDF
105  $this->_isPdf = true;
106 
107  // Build CSS
108  $this->buildCSS(true);
109 
110  // Generate HTML
111  $html = '';
112  //$html .= $this->generateHTMLHeader(false);
113  $html .= $this->generateSheetData();
114  //$html .= $this->generateHTMLFooter();
115 
116  // Default PDF paper size
117  $paperSize = 'A4';
118  $orientation = 'P';
119 
120  // Check for overrides
121  if (is_null($this->getSheetIndex())) {
122  $orientation = $this->_phpExcel->getSheet(0)->getPageSetup()->getOrientation() == 'landscape' ? 'L' : 'P';
123  } else {
124  $orientation = $this->_phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() == 'landscape' ? 'L' : 'P';
125  }
126 
127  // Create PDF
128  $pdf = new TCPDF($orientation, 'pt', $paperSize);
129  $pdf->setPrintHeader(false);
130  $pdf->setPrintFooter(false);
131  $pdf->AddPage();
132  $pdf->SetFont('freesans');
133  $pdf->writeHTML($html);
134 
135  // Document info
136  $pdf->SetTitle($this->_phpExcel->getProperties()->getTitle());
137  $pdf->SetAuthor($this->_phpExcel->getProperties()->getCreator());
138  $pdf->SetSubject($this->_phpExcel->getProperties()->getSubject());
139  $pdf->SetKeywords($this->_phpExcel->getProperties()->getKeywords());
140  $pdf->SetCreator($this->_phpExcel->getProperties()->getCreator());
141 
142  // Write to file
143  fwrite($fileHandle, $pdf->output($pFilename, 'S'));
144 
145  // Close file
146  fclose($fileHandle);
147 
148  PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
149  }
150 
156  public function getTempDir() {
157  return $this->_tempDir;
158  }
159 
167  public function setTempDir($pValue = '') {
168  if (is_dir($pValue)) {
169  $this->_tempDir = $pValue;
170  } else {
171  throw new Exception("Directory does not exist: $pValue");
172  }
173  return $this;
174  }
175 }