public function generatePreviewPdf($controller)
{
Yii::app()->params['wkhtmltopdf_left_margin'] = '10mm';
Yii::app()->params['wkhtmltopdf_right_margin'] = '10mm';
$ec = $this->getElement('Element_OphCoTherapyapplication_ExceptionalCircumstances');
if (!$ec) {
throw new Exception("Exceptional circumstances not found for event ID {$this->event->id}");
}
$template_data = $this->getTemplateData();
$html = '<link rel="stylesheet" type="text/css" href="' . $controller->assetPath . '/css/print.css" />';
if ($ec->hasLeft()) {
$left_template_data = $template_data + $this->getSideSpecificTemplateData('left');
$html .= $this->getPDFContentForSide($controller, $left_template_data, 'left');
}
if ($ec->hasRight()) {
$right_template_data = $template_data + $this->getSideSpecificTemplateData('right');
$html .= $this->getPDFContentForSide($controller, $right_template_data, 'right');
}
$this->event->lock();
if (!$this->event->hasPDF('therapy_application') || @$_GET['html']) {
$wk = new WKHtmlToPDF();
$wk->setDocuments(1);
$wk->setDocRef($this->event->docref);
$wk->setPatient($this->event->episode->patient);
$wk->setBarcode($this->event->barcodeHTML);
$wk->generatePDF($this->event->imageDirectory, 'event', 'therapy_application', $html, (bool) @$_GET['html'], false);
}
$this->event->unlock();
if (@$_GET['html']) {
return Yii::app()->end();
}
$pdf = $this->event->getPDF('therapy_application');
header('Content-Type: application/pdf');
header('Content-Length: ' . filesize($pdf));
readfile($pdf);
}