Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mpdf upgrade #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Classes/Renderer/MPdfRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MPdfRenderer extends AbstractRenderer {
*/
protected function initLibrary() {
if(!class_exists('mPDF', FALSE)) {
$autoloadPath = FLOW_PATH_PACKAGES . 'Libraries/mpdf/mpdf/mpdf.php';
$autoloadPath = FLOW_PATH_PACKAGES . 'Libraries/mpdf/mpdf/src/Mpdf.php';
define('_MPDF_TTFONTDATAPATH', $this->environment->getPathToTemporaryDirectory());
define('_MPDF_TEMP_PATH', $this->environment->getPathToTemporaryDirectory());
if(is_file($autoloadPath)) {
Expand All @@ -45,7 +45,7 @@ protected function convert($html = '') {
$orientation = '';
}

$mpdf=new \mPDF('', $this->getOption('papersize') . $orientation);
$mpdf = new \Mpdf\Mpdf(array('orientation' => $this->getOption('papersize') . $orientation));

$mpdf->debug = $this->getOption('debug');

Expand Down
89 changes: 52 additions & 37 deletions Classes/ViewHelpers/PdfViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,68 @@
namespace KayStrobach\Pdf\ViewHelpers;

/* *
* This script belongs to the TYPO3 Flow package "SBS.LaPo". *
* This script belongs to the TYPO3 Flow package "KayStrobach.Pdf". *
* *
* */

use KayStrobach\Pdf\Renderer\Factory;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Mvc\Exception\StopActionException;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Exception\StopActionException;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use Neos\FluidAdaptor\Core\Rendering\FlowAwareRenderingContextInterface;

class PdfViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper{
class PdfViewHelper extends AbstractViewHelper{

/**
* @var int
*/
protected $errorReporting = 0;
/**
* @var int
*/
protected $errorReporting = 0;

function initializeArguments() {
$this->registerArgument('debug', 'boolean', 'debug or not', 0, 0);
$this->registerArgument('disable', 'boolean', 'disable PDF, output html', 0, 0);
$this->registerArgument('filename', 'string', 'filename for download', 0, 'pdf-' . time() . '.pdf');
$this->registerArgument('papersize', 'string', 'set the papersize', 0, 'A4');
$this->registerArgument('orientation', 'string', 'set the orientation', 0, 'portrait');
$this->registerArgument('basepath', 'string', 'set the basepath', 0, '');
$this->registerArgument('dpi', 'integer', 'set the quality of the pdf', 0, '96');
$this->registerArgument('enableHtml5Parser', 'boolean', 'html5parser or not', 0, 1);
$this->registerArgument('enableCssFloat', 'boolean', 'css floating or not', 0, 1);
$this->registerArgument('renderer', 'string', 'define the pdf renderer', 0, 'MPdf');
}

/**
* @throws \TYPO3\Fluid\Core\ViewHelper\Exception
* @param RenderingContextInterface $renderingContext
* @return void
*/
public function initializeArguments() {
$this->registerArgument('debug', 'boolean', 'debug or not', 0, 0);
$this->registerArgument('disable', 'boolean', 'disable PDF, output html', 0, 0);
$this->registerArgument('filename', 'string', 'filename for download', 0, 'pdf-' . time() . '.pdf');
$this->registerArgument('papersize', 'string', 'set the papersize', 0, 'A4');
$this->registerArgument('orientation', 'string', 'set the orientation', 0, 'portrait');
$this->registerArgument('basepath', 'string', 'set the basepath', 0, '');
$this->registerArgument('dpi', 'integer', 'set the quality of the pdf', 0, '96');
$this->registerArgument('enableHtml5Parser', 'boolean', 'html5parser or not', 0, 1);
$this->registerArgument('enableCssFloat', 'boolean', 'css floating or not', 0, 1);
$this->registerArgument('renderer', 'string', 'define the pdf renderer', 0, 'MPdf');
}

/**
*
* @throws \TYPO3\Flow\Mvc\Exception\StopActionException
* @return string the rendered string
*/
public function render() {
if($this->arguments['disable']) {
return $this->renderChildren();
public function setRenderingContext(RenderingContextInterface $renderingContext)
{
$this->renderingContext = $renderingContext;
$this->templateVariableContainer = $renderingContext->getVariableProvider();
$this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
if ($renderingContext instanceof FlowAwareRenderingContextInterface) {
$this->controllerContext = $renderingContext->getControllerContext();
}
}

$renderer = Factory::get($this->arguments['renderer']);
/**
*
* @throws \Neos\Flow\Mvc\Exception\StopActionException
* @return string the rendered string
*/
public function render() {
if(!$this->arguments['disable']) {

$renderer = Factory::get($this->arguments['renderer']);

$renderer->init($this->arguments);
$renderer->render($this->renderChildren());
$renderer->init($this->arguments);
$renderer->render($this->renderChildren());
} else {
return $this->renderChildren();
}

//use instead of exit ;)
throw new StopActionException();
}
}
//use instead of exit ;)
throw new StopActionException();
}
}