public function copyPage() { $copy = new Core_Pdf_Page($this); $copy->setFont($this->getFont(), $this->getFontSize()); $copy->setMargins($this->getMargins()); $copy->setPaddings($this->getPaddings()); return $copy; }
/** * Render Table * @param Core_Pdf_Page $page * @param $posX * @param $posY * @param bool $inContentArea * @return mixed */ public function render(Core_Pdf_Page $page, $posX, $posY, $inContentArea = true) { if ($this->_headerRow && $this->_rows) { //set header as first row $this->_rows = array_merge($this->_headerRow, $this->_rows); } elseif ($this->_headerRow) { //no rows in this table, just the header $this->_rows = $this->_headerRow; } if ($inContentArea) { $startY = $posY + $page->getMargin(Core_Pdf::TOP); $maxY = $page->getHeight() - $page->getMargin(Core_Pdf::BOTTOM) - $page->getMargin(Core_Pdf::TOP); } else { $startY = $posY; $maxY = $page->getHeight(); $posX -= $page->getMargin(Core_Pdf::LEFT); } $y = $startY; //prerender $this->_preRender($page, $posX, $posY, $inContentArea); foreach ($this->_rows as $row) { //check current position (height) $test = $y - $row->getHeight(); if ($test < $page->getPadding(Core_Pdf::BOTTOM) || $row->hasPageBreak()) { $page = $page->copyPage(); $this->_pages[] = $page; $y = $page->getHeight() - $page->getPadding(Core_Pdf::TOP); if ($this->_headerRow && $this->_repeatHeader) { $header = $this->_rows[0]; //pre-rendered header row (is first row) $header->render($page, $posX, $y); $y -= $header->getHeight() + $header->getBorderLineWidth(Core_Pdf::BOTTOM); } } $row->render($page, $posX, $y); $y -= $row->getHeight() + $row->getBorderLineWidth(Core_Pdf::BOTTOM); $page->currPos = $y; } return $this->_pages; }
private function _drawHeader(Core_Pdf_Page $page, $currentPage) { if (!$this->_header) { return; } if ($page instanceof Core_Pdf_Page) { //set table width $currHeader = clone $this->_header; //check for special place holders $rows = $currHeader->getRows(); foreach ($rows as $key => $row) { $row->setWidth($page->getWidth() - $this->_margin[Core_Pdf::LEFT] - $this->_margin[Core_Pdf::RIGHT]); $cols = $row->getColumns(); $num = 0; foreach ($cols as $col) { if ($col->hasText()) { $num += $col->replaceText('@@CURRENT_PAGE', $currentPage); $num += $col->replaceText('@@TOTAL_PAGES', count($this->pages)); } } if ($num > 0) { $row->setColumns($cols); $currHeader->replaceRow($row, $key); } } $page->addTable($currHeader, $this->_margin[Core_Pdf::LEFT], +$this->_headerYOffset - $this->_margin[Core_Pdf::TOP], false); } }
/** * Positions text vertically (y-axis) adding vertical alignment * Default alignment: TOP * @param Core_Pdf_Page $page * @param int $posY * @return int */ private function _getTextPosY(Core_Pdf_Page $page, $posY) { $y = 0; $lineHeight = $page->getFontHeight() + $this->_textLineSpacing; switch ($this->_vAlign) { case Core_Pdf::BOTTOM: $y = $posY + $this->_height - $this->_padding[Core_Pdf::BOTTOM]; break; case Core_Pdf::MIDDLE: $y = $posY + $this->_height / 2 + $lineHeight / 2; break; default: //TOP $y = $posY - $lineHeight - $this->_padding[Core_Pdf::TOP]; break; } return $y; }
/** * Pre-Render Row * @param Core_Pdf_Page $page * @param $posX * @param $posY * @param bool $inContentArea */ public function preRender(Core_Pdf_Page $page, $posX, $posY, $inContentArea = true) { //pre-render each cell in row and get height $maxHeight = 0; //get width -> auto column width if ($this->_width) { //set given row width $maxRowWidth = $this->_width; } else { //no width given, use available page width if ($inContentArea) { $maxRowWidth = $page->getWidth() - $page->getMargin(Core_Pdf::LEFT) - $page->getMargin(Core_Pdf::RIGHT); } else { $maxRowWidth = $page->getWidth(); } } if ($this->_forceUniformColumnWidth) { $uniformWidth = $maxRowWidth / $this->NumColumns; } else { //check if some colums have specific widths $fixedRowWidth = 0; $dynamicColumns = 0; $dynamicRowWidth = 0; foreach ($this->_cols as $col) { //set font if no font set if (!$col->getFont()) { $col->setFont($this->_font, $this->_fontSize); } $w = $col->getWidth(); if ($w) { //column with specified width $fixedRowWidth += $w; } else { //column with no width specified //pre-render to get a first estimation of width $col->preRender($page, $posX, $posY, $inContentArea); $dynamicRowWidth += $col->getRecommendedWidth(); $dynamicColumns++; } } $freeWidth = $maxRowWidth - $dynamicRowWidth - $fixedRowWidth; if ($dynamicColumns > 0) { $uniformWidth = ($maxRowWidth - $fixedRowWidth) / $dynamicColumns; $freeWidth = $freeWidth / $dynamicColumns; } else { //nothing to distribute (all fixed colum widths) $freeWidth = -1; } if ($freeWidth < 0) { //force text line break for dynamic rows $forceLineBreaking = true; $freeWidth = 0; } else { $forceLineBreaking = false; } } //get max column height foreach ($this->_cols as $col) { //set width ->auto-width=true if (!$col->getWidth()) { //calc width for colums without given width /aproximation if ($this->_forceUniformColumnWidth) { $width = $uniformWidth; } else { if ($col->hasImage()) { //has priority $width = $col->getRecommendedWidth() + $freeWidth; } elseif ($col->hasText()) { if ($forceLineBreaking && $col->getRecommendedWidth() > $uniformWidth) { $width = $uniformWidth; } else { $width = $col->getRecommendedWidth() + $freeWidth; } } } $col->setWidth($width); } if (!$col->getFont()) { $col->setFont($this->_font, $this->_fontSize); } foreach ($this->_cellPadding as $pos => $val) { if (!$col->getPadding($pos)) { $col->setPadding($pos, $val); } } $col->preRender($page, $posX, $posY); $height = $col->getRecommendedHeight(); if ($height > $maxHeight) { $maxHeight = $height; } } //get border thickness of top&bottom row $this->_height = $maxHeight; }