icingaweb2/library/Icinga/File/Pdf.php

62 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Icinga\File;
use DOMPDF;
use DOMDocument;
use DOMXPath;
use Font_Metrics;
use Icinga\Application\Icinga;
use Icinga\Web\StyleSheet;
use Icinga\Web\Url;
use Icinga\Exception\ProgrammingError;
require_once 'vendor/dompdf/dompdf_config.inc.php';
spl_autoload_register('DOMPDF_autoload');
class Pdf extends DOMPDF
{
public $paginateTable = false;
2014-02-21 14:07:32 +01:00
public function __construct()
{
$this->set_paper('A4', 'portrait');
parent::__construct();
}
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');
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirecory() . '/img/', $html);
$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
}