Skip to content

Instantly share code, notes, and snippets.

@revsbech
Created July 9, 2014 07:39
Show Gist options
  • Save revsbech/29bd82b36ba97b0a6f7f to your computer and use it in GitHub Desktop.
Save revsbech/29bd82b36ba97b0a6f7f to your computer and use it in GitHub Desktop.
Example PDF Generation as plugin
<?php
namespace Aris\DailyReports\Controller;
/* *
* This script belongs to the TYPO3 Flow package "Aris.DailyReports". *
* *
* */
use Aris\DailyReports\Utility\WkHtmlToPdfUtility;
use TYPO3\Flow\Annotations as Flow;
class PdfController extends \TYPO3\Flow\Mvc\Controller\ActionController {
/**
* This is a very, very hacky way to do it. We should instead make it such that pages ending in .pdf will render the content
* and pipe it through the PDF generatoe. For now this does the trick (I hope).
*
* @return string
*/
public function renderAsPdfAction() {
$currentUrl = $this->request->getHttpRequest()->getUri();
$title = $this->request->getInternalArgument('__title');
$htmlUrl = str_replace('.pdf', '.html', $currentUrl);
$pdfUtility = new WkHtmlToPdfUtility();
$pathToWkHtmlToPdfBinary = $this->settings['wkHtmlToPdfPath'];
if (is_executable($pathToWkHtmlToPdfBinary) === FALSE) {
throw new \Exception('Unable to call wkHtmlToPdf. Please configure with the full path to the binary in configuration Aris.DailyReports.wkHtmlToPdfPath');
}
$pdfUtility->setOptions(array(
//'bin' => $pathToWkHtmlToPdfBinary . ' --print-media-type',
'bin' => $pathToWkHtmlToPdfBinary . '',
'enableEscaping' => FALSE
));
$pdfUtility->addPage($htmlUrl);
$pdfUtility->send($title . '.pdf');
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment