export_mpdf.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 = stripslashes(api_html_entity_decode($_POST['contentPDF'], ENT_QUOTES, api_get_system_encoding()));
  14. $title_pdf = stripslashes(api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, api_get_system_encoding()));
  15. $html = '
  16. <page backtop="10mm" backbottom="10mm" footer="page">
  17. <page_header>
  18. {TITLE_PDF}<br/><hr/>
  19. </page_header>
  20. {CONTENT_PDF}
  21. <page_footer>
  22. <hr/>
  23. </page_footer>
  24. </page>
  25. ';
  26. $html = api_utf8_encode(str_replace(array('{TITLE_PDF}', '{CONTENT_PDF}'), array($title_pdf, $content_pdf), $html), api_get_system_encoding());
  27. $title_pdf = api_utf8_encode($title_pdf, api_get_system_encoding());
  28. $css_file = api_get_path(TO_SYS, WEB_CSS_PATH).api_get_setting('stylesheets').'/print.css';
  29. if (file_exists($css_file)) {
  30. $css = @file_get_contents($css_file);
  31. } else {
  32. $css = '';
  33. }
  34. $pdf = new mPDF('UTF-8', 'A4', '', '', 32, 25, 27, 25, 16, 13, 'P');
  35. $pdf->directionality = api_get_text_direction();
  36. $pdf->useOnlyCoreFonts = true;
  37. $pdf->SetAuthor('Wiki Chamilo');
  38. $pdf->SetTitle($title_pdf);
  39. $pdf->SetSubject('Exported from Chamilo Wiki');
  40. $pdf->SetKeywords('Chamilo Wiki');
  41. if (!empty($css)) {
  42. $pdf->WriteHTML($css, 1);
  43. $pdf->WriteHTML($html, 2);
  44. } else {
  45. $pdf->WriteHTML($html);
  46. }
  47. if (empty($title_pdf)) {
  48. $title_pdf = 'Exported from Chamilo Wiki';
  49. }
  50. $pdf->Output(replace_dangerous_char($title_pdf.'.pdf'), 'D');