/** * Bulk export: PDF export, based on the HTML export converted to PDF * * @copyright Copyright (C) 2015 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ require_once(APPROOT.'application/pdfpage.class.inc.php'); class PDFBulkExport extends HTMLBulkExport { public function DisplayUsage(Page $oP) { $oP->p(" * pdf format options:"); $oP->p(" *\tfields: (mandatory) the comma separated list of field codes to export (e.g: name,org_id,service_name...)."); $oP->p(" *\tpage_size: (optional) size of the page. One of A4, A3, Letter (default is 'A4')."); $oP->p(" *\tpage_orientation: (optional) the orientation of the page. Either Portrait or Landscape (default is 'Portrait')."); } public function EnumFormParts() { return array_merge(array('pdf_options' => array('pdf_options')), parent::EnumFormParts()); } public function DisplayFormPart(WebPage $oP, $sPartId) { switch($sPartId) { case 'pdf_options': $oP->add('
'); break; default: return parent:: DisplayFormPart($oP, $sPartId); } } protected function GetSelectCtrl($sName, $aValues, $sDictPrefix, $sDefaultValue) { $sCurrentValue = utils::ReadParam($sName, $sDefaultValue, false, 'raw_data'); $aLabels = array(); foreach($aValues as $sVal) { $aLabels[$sVal] = Dict::S($sDictPrefix.$sVal); } asort($aLabels); $sHtml = ''; foreach($aLabels as $sVal => $sLabel) { $sSelected = ($sVal == $sCurrentValue) ? 'selected' : ''; $sHtml .= ''; } $sHtml .= ''; return $sHtml; } public function ReadParameters() { parent::ReadParameters(); $this->aStatusInfo['page_size'] = utils::ReadParam('page_size', 'A4', true, 'raw_data'); $this->aStatusInfo['page_orientation'] = utils::ReadParam('page_orientation', 'L', true); } public function GetHeader() { $this->aStatusInfo['tmp_file'] = $this->MakeTmpFile('data'); $sData = parent::GetHeader(); $hFile = @fopen($this->aStatusInfo['tmp_file'], 'ab'); if ($hFile === false) { throw new Exception('PDFBulkExport: Failed to open temporary data file: "'.$this->aStatusInfo['tmp_file'].'" for writing.'); } fwrite($hFile, $sData."\n"); fclose($hFile); return ''; } public function GetNextChunk(&$aStatus) { $sData = parent::GetNextChunk($aStatus); $hFile = @fopen($this->aStatusInfo['tmp_file'], 'ab'); if ($hFile === false) { throw new Exception('PDFBulkExport: Failed to open temporary data file: "'.$this->aStatusInfo['tmp_file'].'" for writing.'); } fwrite($hFile, $sData."\n"); fclose($hFile); return ''; } public function GetFooter() { $sData = parent::GetFooter(); $oPage = new PDFPage(Dict::Format('Core:BulkExportOf_Class', MetaModel::GetName($this->oSearch->GetClass())), $this->aStatusInfo['page_size'], $this->aStatusInfo['page_orientation']); $oPage->add(file_get_contents($this->aStatusInfo['tmp_file'])); $oPage->add($sData); $sPDF = $oPage->get_pdf(); return $sPDF; } public function GetSupportedFormats() { return array('pdf' => Dict::S('Core:BulkExport:PDFFormat')); } public function GetMimeType() { return 'application/x-pdf'; } public function GetFileExtension() { return 'pdf'; } }