<?php

class solViolette {
	public static function generatePdf($datas,$partial='katao/pdf') {
		$file_name = sprintf('demande de carte sol.pdf');
		$file_path = sfConfig::get('sf_data_dir') . '/pdf/' . $file_name;
		if (!is_dir(sfConfig::get('sf_data_dir') . '/pdf')) {
			mkdir(sfConfig::get('sf_data_dir') . '/pdf');
		}
		// create new PDF document
		$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
		// set default monospaced font
		$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
		// set margins
		$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
		$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
		$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
		// set auto page breaks
		$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
		// set image scale factor
		$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
		// ---------------------------------------------------------
		// set font
		$pdf->SetFont('dejavusans', '', 10);
		// custom
		$pdf->SetMargins(15, 15, 15);
		$pdf->setPrintHeader(false);
		$pdf->setHeaderMargin(0);
		$pdf->setPrintFooter(false);
		$pdf->setFooterMargin(0);
		// $pdf->setAutoPageBreak(false, 1);
		// add a page
		$pdf->AddPage();
		// create some HTML content
		sfLoader::loadHelpers('Partial');

		$html = get_partial($partial, array('datas' => $datas));
		// output the HTML content
		$pdf->writeHTML($html, true, false, true, false, '');
		// reset pointer to the last page
		$pdf->lastPage();
		// ---------------------------------------------------------
		// Close and output PDF document
		$pdf->Output($file_path, 'F');
		// ============================================================+
		// END OF FILE
		// ============================================================+
		return $file_path;
	}
}

?>