Esempio n. 1
0
$DB = new conn();
$DB->connect();
$sql = "select data from reports where id = " . $DB->sanitize($_REQUEST["report_id"]);
$result = $DB->query_scalar($sql);
$time = time();
$css = "<link rel=\"StyleSheet\" href=\"" . $FQDN . "/" . $ROOTPATH . "/CSS/main.css.php?" . $time . "/>";
// Get Querystring params
$output = $DB->sanitize($_REQUEST["output"]);
$footer = $DB->sanitize($_REQUEST["footer"]);
$orient = $DB->sanitize($_REQUEST["orient"]);
$result = str_replace("<HTML><HEAD></HEAD>", "<HTML><HEAD>" . $css . "</HEAD>", $result);
require_once "wk.php";
$pdf = new WKPDF();
$pdf->set_html($result);
if ($footer) {
    $pdf->set_footer("Page [page] of [toPage]");
}
if ($orient) {
    $pdf->set_orientation($orient);
}
$pdf->render();
if ($output) {
    if ($output == "pdf") {
    }
    $pdf->output(WKPDF::$PDF_DOWNLOAD, 'sample.pdf');
} else {
    $pdf->output(WKPDF::$PDF_EMBEDDED, 'sample.pdf');
}
?>

 /**
  * @param $id
  * @throws CHttpException
  */
 public function actionPdf($id)
 {
     Yii::import('application.extensions.less.*');
     $lessc = new lessc();
     $lessc->checkedCompile(Yii::getPathOfAlias('webroot.less') . '/' . 'html2pdf.less', Yii::getPathOfAlias('webroot.css') . '/' . 'html2pdf.css');
     $model = $this->loadModel($id);
     if (!$model) {
         throw new CHttpException(404, 'Property not found');
     }
     $settings = InstructionToPdfSettings::model()->findByAttributes(['instructionId' => $id]);
     if (!$settings) {
         $settings = new InstructionToPdfSettings();
     }
     $pdf = new WKPDF();
     $pdf->setMargins(['top' => '40']);
     $pdf->addResource('css', Yii::getPathOfAlias('webroot.css') . '/' . 'html2pdf.css');
     $cssFiles = ['html2pdf.css'];
     /** @var $browser Browser */
     $browser = Yii::app()->browser;
     if ($browser->getBrowser() == Browser::BROWSER_FIREFOX && $browser->getVersion() >= 19) {
         $pdf->addResource('css', Yii::getPathOfAlias('webroot.css') . '/' . 'helvetica_html2pdf.css');
         $cssFiles[] = 'helvetica_html2pdf.css';
     }
     $pdf->set_html($this->renderPartial('instructionToPDF', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles], true));
     $pdf->set_htmlHeader($this->renderPartial('instructionToPDF/header', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles], true));
     $pdf->set_htmlFooter($this->renderPartial('instructionToPDF/footer', ['model' => $model, 'settings' => $settings, 'pdf' => $pdf, 'cssFiles' => $cssFiles, 'offices' => Office::model()->active()->findAll()], true));
     $pdf->set_orientation(WKPDF::$PDF_PORTRAIT);
     $pdf->render();
     $pdf->output(WKPDF::$PDF_EMBEDDED, null);
 }