<?php
    require_once(BASEPATH.'assets/pdf/Html2Pdf/html2pdf-4.4.0/html2pdf.class.php');

    ob_start();
	include BASEPATH.'form/'.$this->modul.'/'.$this->view;
    $content = ob_get_clean();

    try
    {
		$file = BASEPATH.'pdf/'.$this->data->file.'.pdf';

		if(empty($this->data->paper)){
			$this->data->paper = 'P';
		}
		if(empty($this->data->mb)){
		    $this->data->mb = 0;
		}
		if(empty($this->data->mt)){
		    $this->data->mt = 5;
		}
		if(empty($this->data->mr)){
		    $this->data->mr = 0;
		}
		if(empty($this->data->ml)){
		    $this->data->ml = 0;
		}
		$paperSize = (!empty($this->data->pdf->length) && !empty($this->data->pdf->width)) ? array($this->data->pdf->width, $this->data->pdf->length) : 'A4';
        $html2pdf = new HTML2PDF($this->data->paper, $paperSize, 'fr', true, 'UTF-8', array($this->data->ml, $this->data->mt, $this->data->mr, $this->data->mb));
        $html2pdf->pdf->SetDisplayMode('fullpage');
        $html2pdf->writeHTML($content, isset($_GET['vuehtml']));
        $html2pdf->Output($file, 'F');
		header("Content-type:application/pdf");
		echo file_get_contents($file);		
    }
    catch(HTML2PDF_exception $e) {
        echo $e;
        exit;
    }
