Fix tcpdf bad configuration. define('K_TCPDF_EXTERNAL_CONFIG', true); $_SERVER['DOCUMENT_ROOT'] = '/var/www/'; $kPathMain = getcwd() . '/vendor/tecnickcom/tcpdf/'; define('K_PATH_MAIN', $kPathMain); $kPathUrl = $kPathMain; if (isset($_SERVER['HTTP_HOST']) AND (!empty($_SERVER['HTTP_HOST']))) { if (isset($_SERVER['HTTPS']) AND (!empty($_SERVER['HTTPS'])) AND strtolower($_SERVER['HTTPS'])!='off') { $kPathUrl = 'https://'; } else { $kPathUrl = 'http://'; } $kPathUrl .= $_SERVER['HTTP_HOST']; $kPathUrl .= str_replace('\\', '/', substr(K_PATH_MAIN, (strlen($_SERVER['DOCUMENT_ROOT']) - 1))); } define('K_PATH_URL', $kPathUrl); define('K_PATH_FONTS', K_PATH_MAIN.'fonts/'); define('K_PATH_CACHE', K_PATH_MAIN.'cache/'); define('K_PATH_URL_CACHE', K_PATH_URL.'cache/'); define('K_PATH_IMAGES', K_PATH_MAIN.'images/'); define('K_BLANK_IMAGE', K_PATH_IMAGES.'_blank.png'); define('PDF_PAGE_FORMAT', 'A4'); define('PDF_PAGE_ORIENTATION', 'P'); define('PDF_CREATOR', 'HTML2PDF - TCPDF'); define('PDF_AUTHOR', 'HTML2PDF - TCPDF'); define('PDF_HEADER_TITLE', null); define('PDF_HEADER_STRING', null); define('PDF_HEADER_LOGO', null); define('PDF_HEADER_LOGO_WIDTH', null); define('PDF_UNIT', 'mm'); define('PDF_MARGIN_HEADER', 0); define('PDF_MARGIN_FOOTER', 0); define('PDF_MARGIN_TOP', 0); define('PDF_MARGIN_BOTTOM', 0); define('PDF_MARGIN_LEFT', 0); define('PDF_MARGIN_RIGHT', 0); define('PDF_FONT_NAME_MAIN', 'helvetica'); define('PDF_FONT_SIZE_MAIN', 10); define('PDF_FONT_NAME_DATA', 'helvetica'); define('PDF_FONT_SIZE_DATA', 8); define('PDF_FONT_MONOSPACED', 'courier'); define('PDF_IMAGE_SCALE_RATIO', 1); define('HEAD_MAGNIFICATION', 1); define('K_CELL_HEIGHT_RATIO', 1); define('K_TITLE_MAGNIFICATION', 1); define('K_SMALL_RATIO', 2/3); define('K_THAI_TOPCHARS', true); define('K_TCPDF_CALLS_IN_HTML', false); /** * Base reporting functionality. * @author andre.fourie */ abstract class PdfTemplate { /** * @var \Doctrine\ORM\EntityManager */ protected $em; /** * PDF title. * @var string */ protected $_title = null; /** * PDF logo. * @var string */ protected $_logo = '

EVALUATION SHEET

'; /** * PDF content. * @var array */ private $_html = array(); /** * Current page number. * @var integer */ protected $_page = 0; /** * Options passed. * @var object */ protected $_options = array(); /** * Data passed. * @var array */ protected $_input = array(); /* ---------------------------------------------------------------------- *\ * Standard Interface \* ---------------------------------------------------------------------- */ /** * Process standard format request. * @param array $input * @param array|object $options */ public function process(array $input, $options) { $this->em = \Utility\Registry::getEntityManager(); $this->_input = $input; $this->_options = $options; $this->build(); return $this; } /** * Build the content. */ public function build() {} /* ---------------------------------------------------------------------- *\ * Construction utilities. \* ---------------------------------------------------------------------- */ /** * Move to next page. * @return \Utility\Service\PdfTemplate */ public function nextPage() { $this->_page++; return $this; } /** * Append HTML to template. * @param string $html * @return \Utility\Service\PdfTemplate */ public function append($html) { if (!isset($this->_html[$this->_page])) { $this->_html[$this->_page] = ''; } $this->_html[$this->_page] .= $html; return $this; } /** * Retrieve new PDF data table. * @param array $cellWidths * @param string $tableStyle * @param string $rowStyle * @param string $cellStyle * @return \Utility\Service\PdfElementTable */ public function newTable(array $cellWidths, $tableStyle, $rowStyle, $cellStyle) { return new PdfElementTable($cellWidths, $tableStyle, $rowStyle, $cellStyle); } /** * Retrieve new PDF data table. * Setup new signature section for PDF template. * @param string|null $cellStyle * @return \Utility\Service\PdfElementSignature */ public function newSignatureLine($cellStyle = null) { return new PdfElementSignature($cellStyle); } /* ---------------------------------------------------------------------- *\ * Specifically cater for PDF Template requirements. \* ---------------------------------------------------------------------- */ /** * Retrieve PDF title. * @return string */ public function getTitle() { return $this->_title; } /** * Retrieve PDF content. * @return string */ public function getHtml() { $html = ''; //$logo = ''; foreach ($this->_html as $page) { $html .= '' . $this->_logo . $page . ''; } return $html; } } /* ---------------------------------------------------------------------- *\ * PDF element handlers. \* ---------------------------------------------------------------------- */ /** * Helper utility to build PDF signature line(s). * @author andre.fourie */ class PdfElementSignature { /** * @var array */ protected $_data; /** * @var string */ protected $_cellStyle = 'border-bottom: solid 1px #333;font-size:11px;font-weight:bold;'; /** * Setup new signature section for PDF template. * @param string|null $cellStyle */ public function __construct($cellStyle = null) { !is_null($cellStyle) && $this->_cellStyle = $cellStyle; } public function addSignatureLine($signatureLeft = null, $signatureMiddle = null, $signatureRight = null) { $this->_data[] = array( 'Left' => $signatureLeft, 'Pad1' => null, 'Middle' => $signatureMiddle, 'Pad2' => null, 'Right' => $signatureRight ); return $this; } public function addSignatureText($id, $text) { $this->_data[$id] = $text; return $this; } /** * Publish to HTML. * @return string */ public function publish() { #-> Prepare params. $html = array(); #-> Table header. $html[] = '
'; $html[] = ''; #-> Table content. foreach ($this->_data as $rowId => $signatures) { if (is_numeric($rowId)) { $html[] = ''; $i = 0; foreach ($signatures as $signature) { $i++; $width = (2 == $i || 4 == $i) ? '5%' : '30%'; if (is_null($signature)) { $html[] = ''; } else { empty($signature) && $signature = ' '; $html[] = ''; } } $html[] = ''; $html[] = ''; $i = 0; foreach ($signatures as $signature) { $i++; $width = (2 == $i || 4 == $i) ? '5%' : '30%'; $value = is_null($signature) ? ' ' : $signature; $html[] = ''; } $html[] = ''; } else { $html[] = ''; $html[] = ''; $html[] = ''; } } #-> Table footer. $html[] = '
  
' . $value . '
' . $signatures . '
'; $html[] = '
'; #-> Done. return implode("\n", $html); } } /** * Helper utility to build PDF data table. * @author andre.fourie */ class PdfElementTable { /** * @var array */ protected $_titles = array(); /** * @var array */ protected $_columnHeaders; /** * @var string */ protected $_titleStyle; /** * @var string */ protected $_titleRowStyle; /** * @var string */ protected $_tableStyle; /** * @var string */ protected $_rowStyle; /** * @var string */ protected $_cellStyle; /** * @var array */ protected $_cellWidths; /** * @var array */ protected $_data; /** * Setup new data table for PDF template. * @param array $cellWidths * @param string $tableStyle * @param string $rowStyle * @param string $cellStyle */ public function __construct(array $cellWidths, $tableStyle, $rowStyle, $cellStyle) { $this->_tableStyle = $tableStyle; $this->_rowStyle = $rowStyle; $this->_cellStyle = $cellStyle; $this->_cellWidths = $cellWidths; } /** * Add table title. * @param string $title * @param string|null $titleCellStyle * @param string|null $titleRowStyle * @return \Utility\Service\PdfElementTable */ public function addTitle($title, $titleCellStyle = null, $from = null, $to = null) { $this->_titles[] = array( 'Title' => $title, 'Style' => $titleCellStyle, 'From' => $from, 'To' => $to ); return $this; } /** * Add table title. * @param array $columnHeaders * @param string|null $cellStyle * @return \Utility\Service\PdfElementTable */ public function setColumnHeaders(array $columnHeaders, array $columnSizes, $cellStyle = null) { $this->_columnHeaders = array( 'Columns' => $columnHeaders, 'Sizes' => $columnSizes, 'Style' => $cellStyle ); return $this; } /** * Set value for specific cell. * @param integer $row * @param integer $column * @param unknown $value * @return \Utility\Service\PdfElementTable */ public function setCellValue($row, $column, $value) { $this->_data[$row][$column] = is_null($value) || empty($value) ? ' ' : $value; return $this; } /** * Set dataset. * @param array $dataSet * @return \Utility\Service\PdfElementTable */ public function setDataSet(array $dataSet) { $this->_data = $dataSet; return $this; } /** * Add a key => value dataset to the table. * @param array $dataset * @param number $startAtColumn * @param string $keyStyle * @param string $valueStyle * @return \Utility\Service\PdfElementTable */ public function addKeyValueDataSet(array $dataset, $startAtColumn = 0, $keyStyle = '', $valueStyle = '') { $row = 0; $column = $startAtColumn; foreach ($dataset as $key => $value) { $this->_data[$row][$column] = '' . $key . ''; $this->_data[$row][$column + 1] = '' . $value . ''; $row++; } return $this; } /** * Publish to HTML. * @return string */ public function publish() { #-> Establish table width. $tableWidth = 0; $numColumns = count($this->_cellWidths); foreach ($this->_cellWidths as $columnWidth) { $tableWidth += $columnWidth; } #-> Prepare params. $html = array(); #-> Table header. $html[] = ''; #-> Table title. if (!empty($this->_titles)) { $html[] = ''; $column = 0; foreach ($this->_titles as $title) { if ($title['From'] > $column) { $html[] = ''; } $cellStyle = !is_null($title['Style']) ? $title['Style'] : $this->_cellStyle; $html[] = ''; $column = $title['To'] + 1; } $html[] = ''; } #-> Column headers. if (!is_null($this->_columnHeaders)) { $cellStyle = !is_null($this->_columnHeaders['Style']) ? $this->_columnHeaders['Style'] : $this->_cellStyle; $html[] = ''; foreach ($this->_columnHeaders['Columns'] as $key => $title) { $width = $this->_columnHeaders['Sizes'][$key]; $html[] = ''; } $html[] = ''; } #-> Table content. foreach ($this->_data as $rowId => $rowData) { $html[] = ''; $column = 0; for ($column = 0; $column < $numColumns; $column++) { $value = isset($rowData[$column]) ? $rowData[$column] : ' '; $width = $this->_cellWidths[$column]; $html[] = ''; } $html[] = ''; } #-> Table footer. $html[] = '
 '; $html[] = $title['Title']; $html[] = '
' . $title . '
' . $value . '
'; #-> Done. return implode("\n", $html); } }