2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
|
|
|
|
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-02-05 18:18:22 +01:00
|
|
|
require_once 'vendor/dompdf/dompdf_config.inc.php';
|
2013-06-07 11:44:37 +02:00
|
|
|
|
2014-02-21 11:30:18 +01:00
|
|
|
spl_autoload_register('DOMPDF_autoload');
|
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);
|
|
|
|
|
|
|
|
$request = $controller->getRequest();
|
|
|
|
$layout = $controller->getHelper('layout')->setLayout('pdf');
|
|
|
|
$controller->render();
|
|
|
|
$layout->content = $controller->getResponse();
|
|
|
|
$html = $layout->render();
|
|
|
|
$imgDir = Url::fromPath('img');
|
2014-03-07 16:14:48 +01:00
|
|
|
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirecory() . '/img/', $html);
|
2014-03-06 12:21:11 +01:00
|
|
|
$this->load_html($html);
|
|
|
|
$this->render();
|
|
|
|
$this->stream(
|
|
|
|
sprintf(
|
|
|
|
'%s-%s-%d.pdf',
|
|
|
|
$request->getControllerName(),
|
|
|
|
$request->getActionName(),
|
|
|
|
time()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2014-05-21 00:39:03 +02:00
|
|
|
}
|