export_html2pdf.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * Export html to pdf
  19. * @Author Juan Carlos Raña <herodoto@telefonica.net>
  20. *
  21. */
  22. include '../inc/global.inc.php';
  23. api_block_anonymous_users();
  24. require '../inc/lib/html2pdf/html2pdf.class.php';
  25. $contentPDF = stripslashes(api_html_entity_decode($_POST['contentPDF'], ENT_QUOTES, api_get_system_encoding()));
  26. $titlePDF = stripslashes(api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, api_get_system_encoding()));
  27. ob_start();//activate Output -Buffer
  28. ///////////////////////
  29. ?>
  30. <page backtop="10mm" backbottom="10mm" footer="page">
  31. <page_header>
  32. <?php echo $titlePDF.'<br/><hr/>'?>
  33. </page_header>
  34. <page_footer>
  35. <?php echo '<hr/>'; ?>
  36. </page_footer>
  37. </page>
  38. <?php
  39. /////////////////////
  40. echo $contentPDF;
  41. $htmlbuffer = ob_get_contents();// Store Output-Buffer in one variable
  42. ob_end_clean();// delete Output-Buffer
  43. /////bridge to dokeos lang
  44. $langhtml2pdf = api_get_language_isocode();
  45. // Some code translations are needed.
  46. $langhtml2pdf = strtolower(str_replace('_', '-', $langhtml2pdf));
  47. switch ($langhtml2pdf)
  48. {
  49. case 'uk':
  50. $langhtml2pdf = 'ukr';
  51. break;
  52. case 'pt':
  53. $langhtml2pdf = 'pt_pt';
  54. break;
  55. case 'pt-br':
  56. $langhtml2pdf = 'pt_br';
  57. break;
  58. // Code here other noticed exceptions.
  59. }
  60. // Checking for availability of a corresponding language file.
  61. if (!file_exists(api_get_path(SYS_PATH).'main/inc/lib/html2pdf/langues/'.$langhtml2pdf.'.txt'))
  62. {
  63. // If there was no language file, use the english one.
  64. $langhtml2pdf = 'en';
  65. }
  66. ////
  67. //$script = "
  68. //var rep = app.response('Your name');
  69. //app.alert('Hello '+rep);
  70. //";
  71. $html2pdf = new HTML2PDF('P','A4',$langhtml2pdf, array(30,10,30,10));//array (margin left, margin top, margin right, margin bottom)
  72. //$html2pdf->pdf->IncludeJS($script);
  73. //$html2pdf->pdf->IncludeJS("print(true);");
  74. //$html2pdf->pdf->IncludeJS("app.alert('Generated by Dokeos to PDF');");
  75. //$html2pdf->pdf->SetProtection(array('print'), 'guest');//add a password sample: guest
  76. $html2pdf->pdf->SetAuthor('Wiki Dokeos');
  77. $html2pdf->pdf->SetTitle($titlePDF);
  78. $html2pdf->pdf->SetSubject('Exported from Dokeos Wiki');
  79. $html2pdf->pdf->SetKeywords('Dokeos Wiki');
  80. //$html2pdf->WriteHTML(utf8_decode($htmlbuffer));
  81. $html2pdf->WriteHTML($htmlbuffer);
  82. $html2pdf->Output($titlePDF.'.pdf', 'D');
  83. ?>