solViolette.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. class solViolette {
  3. public static function generatePdf($datas,$partial='katao/pdf') {
  4. $file_name = sprintf('demande de carte sol.pdf');
  5. $file_path = sfConfig::get('sf_data_dir') . '/pdf/' . $file_name;
  6. if (!is_dir(sfConfig::get('sf_data_dir') . '/pdf')) {
  7. mkdir(sfConfig::get('sf_data_dir') . '/pdf');
  8. }
  9. // create new PDF document
  10. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  11. // set default monospaced font
  12. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  13. // set margins
  14. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  15. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  16. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  17. // set auto page breaks
  18. $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
  19. // set image scale factor
  20. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  21. // ---------------------------------------------------------
  22. // set font
  23. $pdf->SetFont('dejavusans', '', 10);
  24. // custom
  25. $pdf->SetMargins(15, 15, 15);
  26. $pdf->setPrintHeader(false);
  27. $pdf->setHeaderMargin(0);
  28. $pdf->setPrintFooter(false);
  29. $pdf->setFooterMargin(0);
  30. // $pdf->setAutoPageBreak(false, 1);
  31. // add a page
  32. $pdf->AddPage();
  33. // create some HTML content
  34. sfLoader::loadHelpers('Partial');
  35. $html = get_partial($partial, array('datas' => $datas));
  36. // output the HTML content
  37. $pdf->writeHTML($html, true, false, true, false, '');
  38. // reset pointer to the last page
  39. $pdf->lastPage();
  40. // ---------------------------------------------------------
  41. // Close and output PDF document
  42. $pdf->Output($file_path, 'F');
  43. // ============================================================+
  44. // END OF FILE
  45. // ============================================================+
  46. return $file_path;
  47. }
  48. }
  49. ?>