Skip to content

Commit

Permalink
[TASK] cgl + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kaystrobach committed Dec 10, 2018
1 parent 4b86aec commit ccf9439
Showing 1 changed file with 132 additions and 52 deletions.
184 changes: 132 additions & 52 deletions Classes/View/PdfTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,143 @@
use KayStrobach\Pdf\Renderer\Factory;
use Neos\Flow\Annotations as Flow;
use Neos\FluidAdaptor\View\TemplateView;
use Neos\Flow\Mvc\View\ViewInterface;

class PdfTemplateView extends TemplateView {
/**
* @var array
*/
protected $supportedOptions = array(
'templateRootPathPattern' => array('@packageResourcesPath/Private/Templates', 'Pattern to be resolved for "@templateRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"', 'string'),
'partialRootPathPattern' => array('@packageResourcesPath/Private/Partials', 'Pattern to be resolved for "@partialRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"', 'string'),
'layoutRootPathPattern' => array('@packageResourcesPath/Private/Layouts', 'Pattern to be resolved for "@layoutRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"', 'string'),
class PdfTemplateView extends TemplateView implements ViewInterface{
/**
* @var array
*/
protected $supportedOptions = [
'templateRootPathPattern' => [
'@packageResourcesPath/Private/Templates',
'Pattern to be resolved for "@templateRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"',
'string'
],
'partialRootPathPattern' => [
'@packageResourcesPath/Private/Partials',
'Pattern to be resolved for "@partialRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"',
'string'
],
'layoutRootPathPattern' => [
'@packageResourcesPath/Private/Layouts',
'Pattern to be resolved for "@layoutRoot" in the other patterns. Following placeholders are supported: "@packageResourcesPath"',
'string'
],
'templateRootPaths' => [
[],
'Path(s) to the template root. If null, then $this->options["templateRootPathPattern"] will be used to determine the path',
'array'
],
'partialRootPaths' => [
[],
'Path(s) to the partial root. If null, then $this->options["partialRootPathPattern"] will be used to determine the path',
'array'
],
'layoutRootPaths' => [
[],
'Path(s) to the layout root. If null, then $this->options["layoutRootPathPattern"] will be used to determine the path',
'array'
],
'templatePathAndFilenamePattern' => [
'@templateRoot/@subpackage/@controller/@action.@format',
'File pattern for resolving the template file. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@action", "@format"',
'string'
],
'partialPathAndFilenamePattern' => [
'@partialRoot/@subpackage/@partial.@format',
'Directory pattern for global partials. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@partial", "@format"',
'string'
],
'layoutPathAndFilenamePattern' => [
'@layoutRoot/@layout.@format',
'File pattern for resolving the layout. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@layout", "@format"',
'string'
],
'templatePathAndFilename' => [
null,
'Path and filename of the template file. If set, overrides the templatePathAndFilenamePattern',
'string'
],
'layoutPathAndFilename' => [
null,
'Path and filename of the layout file. If set, overrides the layoutPathAndFilenamePattern',
'string'
],
'debug' => [
false,
'debug or not',
'boolean'
],
'disable' => [
false,
'disable PDF, output html',
'boolean'
],
'filename' => [
'[email protected]',
'filename for download',
'string'
],
'papersize' => [
'A4',
'set the papersize',
'string'
],
'orientation' => [
'portrait',
'set the orientation',
'string'
],
'basepath' => [
'',
'set the basepath',
'string'
],
'dpi' => [
120,
'set the quality of the pdf',
'integer'
],
'enableHtml5Parser' => [
true,
'html5parser or not',
'boolean'
],
'enableCssFloat' => [
true,
'css floating or not',
'boolean'
],
'renderer' => [
'MPdf',
'define the pdf renderer',
'string'
],
];

'templateRootPaths' => array(NULL, 'Path(s) to the template root. If NULL, then $this->options["templateRootPathPattern"] will be used to determine the path', 'array'),
'partialRootPaths' => array(NULL, 'Path(s) to the partial root. If NULL, then $this->options["partialRootPathPattern"] will be used to determine the path', 'array'),
'layoutRootPaths' => array(NULL, 'Path(s) to the layout root. If NULL, then $this->options["layoutRootPathPattern"] will be used to determine the path', 'array'),
/**
* @Flow\Inject
* @var \KayStrobach\Pdf\Renderer\MPdfRenderer
*/
protected $renderHelper;

'templatePathAndFilenamePattern' => array('@templateRoot/@subpackage/@controller/@action.@format', 'File pattern for resolving the template file. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@action", "@format"', 'string'),
'partialPathAndFilenamePattern' => array('@partialRoot/@subpackage/@partial.@format', 'Directory pattern for global partials. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@partial", "@format"', 'string'),
'layoutPathAndFilenamePattern' => array('@layoutRoot/@layout.@format', 'File pattern for resolving the layout. Following placeholders are supported: "@templateRoot", "@partialRoot", "@layoutRoot", "@subpackage", "@layout", "@format"', 'string'),
/**
* @param string $actionName
* @return string
*/
public function render($actionName = null) {
$this->assign('PAGENO', '{PAGENO}');
$this->assign('nbpg', '{nbpg}');

'templatePathAndFilename' => array(NULL, 'Path and filename of the template file. If set, overrides the templatePathAndFilenamePattern', 'string'),
'layoutPathAndFilename' => array(NULL, 'Path and filename of the layout file. If set, overrides the layoutPathAndFilenamePattern', 'string'),
/** @var \Neos\Flow\Http\Response $response */
$response = $this->controllerContext->getResponse();

'debug' => array(FALSE, 'debug or not', 'boolean'),
'disable' => array(FALSE, 'disable PDF, output html', 'boolean'),
'filename' => array('[email protected]', 'filename for download', 'string'),
'papersize' => array('A4', 'set the papersize', 'string'),
'orientation' => array('portrait', 'set the orientation', 'string'),
'basepath' => array('', 'set the basepath', 'string'),
'dpi' => array(120, 'set the quality of the pdf', 'integer'),
'enableHtml5Parser' => array(TRUE, 'html5parser or not', 'boolean'),
'enableCssFloat' => array(TRUE, 'css floating or not', 'boolean'),
'renderer' => array('MPdf', 'define the pdf renderer', 'string'),
$renderer = Factory::get($this->options['renderer']);
$renderer->init($this->options);

);
$response->setHeader('Content-Disposition', 'inline; filename="fname.pdf"');
$response->setHeader('Content-Type', 'application/pdf; name="fileName.pdf"');

/**
* @Flow\Inject
* @var \KayStrobach\Pdf\Renderer\MPdfRenderer
*/
protected $renderHelper;

/**
* @param string $actionName
* @return string
*/
public function render($actionName = NULL) {
$this->assign('PAGENO', '{PAGENO}');
$this->assign('nbpg', '{nbpg}');

/** @var \Neos\Flow\Http\Response $response */
$response = $this->controllerContext->getResponse();

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

$response->setHeader('Content-Disposition', 'inline; filename="fname.pdf"');
$response->setHeader('Content-Type', 'application/pdf; name="fileName.pdf"');

return $renderer->render(parent::render($actionName));
}
return $renderer->render(parent::render($actionName));
}
}

0 comments on commit ccf9439

Please sign in to comment.