Skip to content

Commit

Permalink
PDF options for row height paddings (#245)
Browse files Browse the repository at this point in the history
* added padding and content_padding options for pdf renderer

* adds default padding and content_padding values

* renames content_padding to contentPadding

* adds option to specify height of header rows

* fixes cs error
  • Loading branch information
blacktemplar authored and ThaDafinser committed Oct 18, 2016
1 parent f85a180 commit 42cd977
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
'header' => [
'font' => 'helvetica',
'size' => 11,
'height' => 7,

'color' => [
0,
Expand All @@ -171,6 +172,8 @@
'data' => [
'font' => 'helvetica',
'size' => 11,
'padding' => 4,
'contentPadding' => 2,

'color' => [
0,
Expand Down
2 changes: 1 addition & 1 deletion src/ZfcDatagrid/Column/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function removeAction($key = null)
}

/**
*
*
*/
public function clearActions()
{
Expand Down
13 changes: 9 additions & 4 deletions src/ZfcDatagrid/Renderer/TCPDF/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,23 @@ protected function getRowHeight(array $row)
{
$optionsRenderer = $this->getOptionsRenderer();
$sizePoint = $optionsRenderer['style']['data']['size'];
$padding = $optionsRenderer['style']['data']['padding'];
$contentPadding = $optionsRenderer['style']['data']['contentPadding'];

// Points to MM
$size = $sizePoint / 2.83464566929134;

$pdf = $this->getPdf();

$rowHeight = $size + 4;
$rowHeight = $size + $padding;
foreach ($this->getColumnsToExport() as $col) {
/* @var $col \ZfcDatagrid\Column\AbstractColumn */

switch (get_class($col->getType())) {

case 'ZfcDatagrid\Column\Type\Image':
// "min" height for such a column
$height = $col->getType()->getResizeHeight() + 2;
$height = $col->getType()->getResizeHeight() + $contentPadding;
break;

default:
Expand All @@ -246,7 +249,7 @@ protected function getRowHeight(array $row)
$height = $pdf->getStringHeight($col->getWidth(), $value);

// include borders top/bottom
$height += 2;
$height += $contentPadding;
break;
}

Expand All @@ -260,6 +263,8 @@ protected function getRowHeight(array $row)

protected function printTableHeader()
{
$optionsRenderer = $this->getOptionsRenderer();
$height = $optionsRenderer['style']['header']['height'];
$this->setFontHeader();

$pdf = $this->getPdf();
Expand All @@ -275,7 +280,7 @@ protected function printTableHeader()
$label = $this->translate($col->getLabel());

// Do not wrap header labels, it will look very ugly, that's why max height is set to 7!
$pdf->MultiCell($col->getWidth(), 7, $label, 1, $this->getTextAlignment(), true, 2, $x, $y, true, 0, false, true, 7);
$pdf->MultiCell($col->getWidth(), $height, $label, 1, $this->getTextAlignment(), true, 2, $x, $y, true, 0, false, true, 7);
}
}

Expand Down

0 comments on commit 42cd977

Please sign in to comment.