2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013 Icinga Development Team | GPLv2+ */
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2013-07-12 11:58:58 +02:00
|
|
|
namespace Icinga\File;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2017-12-13 11:19:45 +01:00
|
|
|
use Dompdf\Autoloader;
|
2016-11-10 14:59:18 +01:00
|
|
|
use Dompdf\Dompdf;
|
|
|
|
use Dompdf\Options;
|
2014-03-06 12:21:11 +01:00
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
2016-11-10 14:59:18 +01:00
|
|
|
use Icinga\Web\Url;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2017-12-13 11:19:45 +01:00
|
|
|
call_user_func(function () {
|
|
|
|
/**
|
|
|
|
* @package dompdf
|
|
|
|
* @link http://dompdf.github.com/
|
|
|
|
* @author Benj Carson <benjcarson@digitaljunkies.ca>
|
|
|
|
* @author Fabien Ménager <fabien.menager@gmail.com>
|
|
|
|
* @author Alexander A. Klimov <alexander.klimov@icinga.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
|
|
|
|
*/
|
|
|
|
|
2018-02-05 17:56:42 +01:00
|
|
|
$baseDir = Icinga::app()->getBaseDir('library/vendor/dompdf');
|
2017-12-13 11:19:45 +01:00
|
|
|
|
|
|
|
require_once "$baseDir/lib/html5lib/Parser.php";
|
|
|
|
require_once "$baseDir/lib/php-font-lib/src/FontLib/Autoloader.php";
|
|
|
|
require_once "$baseDir/lib/php-svg-lib/src/autoload.php";
|
|
|
|
require_once "$baseDir/src/Autoloader.php";
|
|
|
|
|
|
|
|
Autoloader::register();
|
|
|
|
});
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2016-11-10 14:59:18 +01:00
|
|
|
class Pdf
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-03-06 12:21:11 +01:00
|
|
|
protected function assertNoHeadersSent()
|
|
|
|
{
|
|
|
|
if (headers_sent()) {
|
|
|
|
throw new ProgrammingError(
|
|
|
|
'Could not send pdf-response, content already written to output.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderControllerAction($controller)
|
|
|
|
{
|
|
|
|
$this->assertNoHeadersSent();
|
|
|
|
ini_set('memory_limit', '384M');
|
|
|
|
ini_set('max_execution_time', 300);
|
2015-02-11 15:14:40 +01:00
|
|
|
$viewRenderer = $controller->getHelper('viewRenderer');
|
|
|
|
$controller->render(
|
|
|
|
$viewRenderer->getScriptAction(),
|
|
|
|
$viewRenderer->getResponseSegment(),
|
|
|
|
$viewRenderer->getNoController()
|
|
|
|
);
|
2014-03-06 12:21:11 +01:00
|
|
|
$layout = $controller->getHelper('layout')->setLayout('pdf');
|
|
|
|
$layout->content = $controller->getResponse();
|
|
|
|
$html = $layout->render();
|
|
|
|
$imgDir = Url::fromPath('img');
|
2017-01-27 14:48:59 +01:00
|
|
|
$html = preg_replace(
|
|
|
|
'~src="' . $imgDir . '/~',
|
|
|
|
'src="' . Icinga::app()->getBootstrapDirectory() . '/img/',
|
|
|
|
$html
|
|
|
|
);
|
2016-11-10 14:59:18 +01:00
|
|
|
$options = new Options();
|
|
|
|
$options->set('defaultPaperSize', 'A4');
|
|
|
|
$dompdf = new Dompdf($options);
|
|
|
|
$dompdf->loadHtml($html);
|
|
|
|
$dompdf->render();
|
2015-02-11 15:14:40 +01:00
|
|
|
$request = $controller->getRequest();
|
2016-11-10 14:59:18 +01:00
|
|
|
$dompdf->stream(
|
2014-03-06 12:21:11 +01:00
|
|
|
sprintf(
|
2016-11-10 14:59:18 +01:00
|
|
|
'%s-%s-%d',
|
2014-03-06 12:21:11 +01:00
|
|
|
$request->getControllerName(),
|
|
|
|
$request->getActionName(),
|
|
|
|
time()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-06-05 02:10:49 +02:00
|
|
|
}
|