public function __construct($labels = array()) { $cols = null; foreach ($labels as $label) { $col = new Core_Pdf_Table_Column(); $col->setText($label); $cols[] = $col; } if ($cols) { $this->setColumns($cols); } //set default alignment $this->_align = Core_Pdf::CENTER; //set default borders $style = new Zend_Pdf_Style(); $style->setLineWidth(2); $this->setBorder(Core_Pdf::BOTTOM, $style); $this->setCellPaddings(array(5, 5, 5, 5)); //set default font $this->_font = Zend_Pdf_Font::fontWithName(ZEND_Pdf_Font::FONT_HELVETICA_BOLD); $this->_fontSize = 12; }
/** * Pre-Render Table * * @param Core_Pdf_Page $page * @param int $posX * @param int $posY * @param bool $inContentArea */ private function _preRender(Core_Pdf_Page $page, $posX, $posY, $inContentArea = true) { //get auto-colum widths $colWidths = array(); foreach ($this->_rows as $row) { //check for colspan's $newDumCoreCells = array(); foreach ($row->getColumns() as $idx => $col) { $colWidths[$idx] = $col->getWidth(); //store widht ->for dummy cells if ($col->getColspan() > 1) { //insert new cell, for each spanning column $newDumCoreCells[$idx] = $col; } } //insert dummy cells foreach ($newDumCoreCells as $idx => $col) { for ($i = 1; $i < $col->getColspan(); $i++) { //new col $nCol = new Core_Pdf_Table_Column(); $nCol->setText(''); if (isset($colWidths[$idx + 1])) { $nCol->setWidth($colWidths[$idx + 1]); } $row->insertColumn($nCol, $idx + 1); } } //pre-render row $row->preRender($page, $posX, $posY, $inContentArea); $posY += $row->getHeight() + $row->getBorderLineWidth(Core_Pdf::BOTTOM); } //set max col width $maxColWidth = array(); foreach ($this->_rows as $row) { //get columns max width $maxColWidth = array(); foreach ($row->getColumns() as $idx => $col) { $width = $col->getWidth(); if (!isset($maxColWidth[$idx]) || $width > $maxColWidth[$idx]) { $maxColWidth[$idx] = $width; } } } //set uniform column widht for all rows foreach ($this->_rows as $row) { foreach ($row->getColumns() as $idx => $col) { if (!$col->_manualWidth) { $col->setWidth($maxColWidth[$idx]); } } } }