diff --git a/field_plugins/views_pdf_handler_page_break.inc b/field_plugins/views_pdf_handler_page_break.inc index 3018993..fc3b534 100644 --- a/field_plugins/views_pdf_handler_page_break.inc +++ b/field_plugins/views_pdf_handler_page_break.inc @@ -16,6 +16,7 @@ class views_pdf_handler_page_break extends views_handler_field { protected $countRecords = 0; + protected $currentPageRow = 1; /** * This method is used to query data. In our case @@ -36,6 +37,7 @@ class views_pdf_handler_page_break extends views_handler_field { $options = parent::option_definition(); $options['last_row'] = array('default' => FALSE); + $options['every_nth'] = array('default' => 1); return $options; } @@ -52,6 +54,14 @@ class views_pdf_handler_page_break extends views_handler_field { '#default_value' => $this->options['last_row'], '#description' => t('Check this box to not add new page on last row.'), ); + $form['every_nth'] = array( + '#type' => 'textfield', + '#title' => t('Insert break after how many rows?'), + '#size' => 10, + '#default_value' => $this->options['every_nth'], + '#element_validate' => array('element_validate_integer_positive'), + '#description' => t('Enter a value greater than 1 if you want to have multiple rows on one page') + ); } /** @@ -65,7 +75,15 @@ class views_pdf_handler_page_break extends views_handler_field { } $this->countRecords++; - $this->view->pdf->addPage(); + if ($this->currentPageRow == $this->options['every_nth'] || $this->countRecords == $this->view->numberOfRecords) { + $this->view->pdf->addPage(); + // Tell the rendering template that we just set a new page break: + $this->view->pdf->setPageBreakJustInserted(true); + } + $this->currentPageRow++; + if ($this->currentPageRow > $this->options['every_nth']) { + $this->currentPageRow = 1; + } return ''; } diff --git a/views_pdf_template.php b/views_pdf_template.php index 89345a7..b21637c 100644 --- a/views_pdf_template.php +++ b/views_pdf_template.php @@ -43,6 +43,7 @@ class PdfTemplate extends FPDI { protected $headerFooterOptions = array(); protected $lastWritingPage = 1; protected $lastWritingPositions; + protected $pageBreakJustInserted = false; protected static $defaultFontList = array( 'almohanad' => 'AlMohanad', @@ -138,6 +139,10 @@ class PdfTemplate extends FPDI { ); } + public function setPageBreakJustInserted($bool) { + $this->pageBreakJustInserted = $bool; + } + /** * This method must be overriden, in the other case, some * output is printed to the header. @@ -262,13 +267,18 @@ class PdfTemplate extends FPDI { // Determine the last writting y coordinate, if we are on a new // page we need to reset it back to the top margin. - if ($this->lastWritingPage != $this->getPage() OR ($this->y + $this->bMargin) > $pageDim['hk']) { + if ($this->lastWritingPage != $this->getPage() OR ($this->y + $this->bMargin) > $pageDim['hk'] OR $this->pageBreakJustInserted) { $last_writing_y_position = $this->tMargin; } else { $last_writing_y_position = $this->y; } + if ($this->pageBreakJustInserted) { + $options['position']['object'] = 'page'; + $this->pageBreakJustInserted = false; + } + // Determin the x and y coordinates if ($options['position']['object'] == 'last_position') { $x = $this->x + $options['position']['x'];