2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 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
|
|
|
|
2014-02-21 11:30:18 +01:00
|
|
|
use DOMPDF;
|
|
|
|
use DOMDocument;
|
|
|
|
use DOMXPath;
|
2014-03-06 12:21:11 +01:00
|
|
|
use Font_Metrics;
|
|
|
|
use Icinga\Application\Icinga;
|
|
|
|
use Icinga\Web\StyleSheet;
|
|
|
|
use Icinga\Web\Url;
|
|
|
|
use Icinga\Exception\ProgrammingError;
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2014-11-13 20:10:24 +01:00
|
|
|
require_once 'dompdf/dompdf_config.inc.php';
|
|
|
|
require_once 'dompdf/include/autoload.inc.php';
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2014-02-05 18:18:22 +01:00
|
|
|
class Pdf extends DOMPDF
|
2013-06-07 11:44:37 +02:00
|
|
|
{
|
2014-02-21 11:30:18 +01:00
|
|
|
public $paginateTable = false;
|
2014-02-11 17:48:31 +01:00
|
|
|
|
2014-02-21 14:07:32 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2014-03-06 12:21:11 +01:00
|
|
|
$this->set_paper('A4', 'portrait');
|
2014-02-05 18:18:22 +01:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
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');
|
2014-11-12 17:14:09 +01:00
|
|
|
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
|
2014-03-06 12:21:11 +01:00
|
|
|
$this->load_html($html);
|
|
|
|
$this->render();
|
2015-02-11 15:14:40 +01:00
|
|
|
$request = $controller->getRequest();
|
2014-03-06 12:21:11 +01:00
|
|
|
$this->stream(
|
|
|
|
sprintf(
|
|
|
|
'%s-%s-%d.pdf',
|
|
|
|
$request->getControllerName(),
|
|
|
|
$request->getActionName(),
|
|
|
|
time()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-06-05 02:10:49 +02:00
|
|
|
}
|