export_mpdf.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /* For licensing terms, see /chamilo_license.txt */
  3. /**
  4. * Export html to pdf
  5. * @author Juan Carlos Raña <herodoto@telefonica.net>, initial code, 2009
  6. * @author Ivan Tcholakov <ivantcholakov@gmail.com>, 2010
  7. */
  8. require '../inc/global.inc.php';
  9. api_protect_course_script();
  10. api_block_anonymous_users();
  11. define('_MPDF_PATH', api_get_path(LIBRARY_PATH).'mpdf/');
  12. require_once _MPDF_PATH.'mpdf.php';
  13. $content_pdf = api_html_entity_decode($_POST['contentPDF'], ENT_QUOTES, api_get_system_encoding());
  14. $title_pdf = api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, api_get_system_encoding());
  15. $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
  16. $content_pdf = api_utf8_encode($content_pdf, api_get_system_encoding());
  17. $html='
  18. <!-- defines the headers/footers - this must occur before the headers/footers are set -->
  19. <!--mpdf
  20. <pageheader name="odds" content-left="'.$title_pdf.'" header-style-left="color: #880000; font-style: italic;" line="1" />
  21. <pagefooter name="odds" content-right="{PAGENO}/{nb}" line="1" />
  22. <!-- set the headers/footers - they will occur from here on in the document -->
  23. <!--mpdf
  24. <setpageheader name="odds" page="odd" value="on" show-this-page="1" />
  25. <setpagefooter name="odds" page="O" value="on" />
  26. mpdf-->'.$content_pdf;
  27. $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  28. if (file_exists($css_file)) {
  29. $css = @file_get_contents($css_file);
  30. } else {
  31. $css = '';
  32. }
  33. $pdf = new mPDF('UTF-8', 'A4', '', '', 30, 20, 27, 25, 16, 13, 'P');
  34. $pdf->directionality = api_get_text_direction();
  35. $pdf->useOnlyCoreFonts = true;
  36. $pdf->SetAuthor('Wiki Chamilo');
  37. $pdf->SetTitle($title_pdf);
  38. $pdf->SetSubject('Exported from Chamilo Wiki');
  39. $pdf->SetKeywords('Chamilo Wiki');
  40. if (!empty($css)) {
  41. $pdf->WriteHTML($css, 1);
  42. $pdf->WriteHTML($html, 2);
  43. } else {
  44. $pdf->WriteHTML($html);
  45. }
  46. if (empty($title_pdf)) {
  47. $title_pdf = 'Exported from Chamilo Wiki';
  48. }
  49. $pdf->Output(replace_dangerous_char($title_pdf.'.pdf'), 'D');