Skip to content

Commit

Permalink
Fixes importPage does not work with autoPageBreak=1, resolves #41
Browse files Browse the repository at this point in the history
  • Loading branch information
maechler committed May 4, 2018
1 parent 5cdcff6 commit 9609775
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## 1.5.0 - Not yet released
- Updates documentation
- Adds automatic hyphenation to all textual ViewHelpers, [#44](https://github.com/bithost-gmbh/pdfviewhelpers/issues/44)
- Adds (optional) automatic hyphenation to all textual ViewHelpers, [#44](https://github.com/bithost-gmbh/pdfviewhelpers/issues/44)
- Adds support for absolute, relative and TYPO3 EXT: paths, [#43](https://github.com/bithost-gmbh/pdfviewhelpers/issues/43)
- Adds format to PageViewHelper, [#42](https://github.com/bithost-gmbh/pdfviewhelpers/issues/42)
- Fixes importPage does not work with autoPageBreak=1, [#41](https://github.com/bithost-gmbh/pdfviewhelpers/issues/41)

## 1.4.0 - April 10, 2018
- Fixes posX and posY not working, [#37](https://github.com/bithost-gmbh/pdfviewhelpers/issues/37) (Thanks [@PeterSchuhmann](https://github.com/PeterSchuhmann))
Expand Down
31 changes: 31 additions & 0 deletions Classes/Model/EmptyFPDI.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
* @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Marin <esteban.marin@bithost.ch>
*/
class EmptyFPDI extends FPDI {
/**
* Indicating whether the current page is using a template.
* This is needed to automatically add the template on an automatic page break.
*
* @var bool
*/
protected $importTemplateOnThisPage = false;

/**
* @return void
*/
Expand All @@ -48,4 +56,27 @@ public function Header() {
public function Footer() {

}

/**
* Fixes importPage not working with autoPageBreak=1, see https://github.com/bithost-gmbh/pdfviewhelpers/issues/41
*
* @inheritdoc
*/
public function AddPage($orientation = '', $format = '', $rotationOrKeepmargins = false, $tocpage = false)
{
parent::AddPage($orientation, $format, $rotationOrKeepmargins, $tocpage);

if ($this->importTemplateOnThisPage && $this->tpl !== 0) {
$this->useTemplate($this->tpl);
}
}

/**
* @param bool $importTemplateOnThisPage
*
* @return void
*/
public function setImportTemplateOnThisPage($importTemplateOnThisPage) {
$this->importTemplateOnThisPage = $importTemplateOnThisPage;
}
}
16 changes: 14 additions & 2 deletions Classes/ViewHelpers/PageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* * */

use Bithost\Pdfviewhelpers\Exception\Exception;
use Bithost\Pdfviewhelpers\Model\EmptyFPDI;
use FPDI;

/**
Expand Down Expand Up @@ -68,8 +69,14 @@ public function initialize() {
*/
public function render() {
$templateId = -1;
$hasImportedPage = !empty($this->arguments['importPage']);

if (!empty($this->arguments['importPage'])) {
//reset import template on this page in order to avoid duplicate usage
if ($this->getPDF() instanceof EmptyFPDI) {
$this->getPDF()->setImportTemplateOnThisPage(false);
}

if ($hasImportedPage) {
if ($this->getPDF() instanceof FPDI) {
$templateId = $this->getPDF()->importPage($this->arguments['importPage']);
} else {
Expand All @@ -79,10 +86,15 @@ public function render() {

$this->getPDF()->AddPage($this->arguments['orientation'], $this->arguments['format']);

if (!empty($this->arguments['importPage'])) {
if ($hasImportedPage) {
$this->getPDF()->useTemplate($templateId);
}

//set whether to import the template on an automatic page break or not
if ($this->getPDF() instanceof EmptyFPDI) {
$this->getPDF()->setImportTemplateOnThisPage($hasImportedPage);
}

$this->renderChildren();
}

Expand Down
1 change: 0 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?php


$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting']['tx_pdfviewhelpers'] = \Bithost\Pdfviewhelpers\Hooks\TypoScriptFrontendController::class.'->isOutputting';

0 comments on commit 9609775

Please sign in to comment.