/**
* Sends response to output.
* @return void
*/
function send(\Nette\Http\IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
{
if ($this->source instanceof ITemplate) {
$this->source->pdfResponse = $this;
$this->source->mPDF = $this->getMPDF();
$html = $this->source->__toString();
} else {
$html = $this->source;
}
// Fix: $html can't be empty (mPDF generates Fatal error)
if (empty($html)) {
$html = "<html><body></body></html>";
}
$mpdf = $this->getMPDF();
$mpdf->biDirectional = $this->multiLanguage;
$mpdf->SetAuthor($this->documentAuthor);
$mpdf->SetTitle($this->documentTitle);
$mpdf->SetDisplayMode($this->displayZoom, $this->displayLayout);
$mpdf->showImageErrors = true;
// @see: http://mpdf1.com/manual/index.php?tid=121&searchstring=writeHTML
if ($this->ignoreStylesInHTMLDocument) {
// copied from mPDF -> removes comments
$html = preg_replace('/<!--mpdf/i', '', $html);
$html = preg_replace('/mpdf-->/i', '', $html);
$html = preg_replace('/<\\!\\-\\-.*?\\-\\->/s', '', $html);
// deletes all <style> tags
$parsedHtml = new simple_html_dom($html);
foreach ($parsedHtml->find("style") as $el) {
$el->outertext = "";
}
$html = $parsedHtml->__toString();
$mode = 2;
// If <body> tags are found, all html outside these tags are discarded, and the rest is parsed as content for the document. If no <body> tags are found, all html is parsed as content. Prior to mPDF 4.2 the default CSS was not parsed when using mode #2
} else {
$mode = 0;
// Parse all: HTML + CSS
}
// Add content
$mpdf->WriteHTML($html, $mode);
// Add styles
if (!empty($this->styles)) {
$mpdf->WriteHTML($this->styles, 1);
}
$this->onBeforeComplete($mpdf);
$mpdf->Output(\Nette\Utils\Strings::webalize($this->documentTitle), 'I');
}