export_html2pdf.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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, $charset));
  26. $titlePDF=stripslashes(api_html_entity_decode($_POST['titlePDF'], ENT_QUOTES, $charset));
  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 = Database :: get_language_isocode($language_interface);
  45. // Some code translations are needed.
  46. $langhtml2pdf = strtolower(str_replace('_', '-', $langhtml2pdf));
  47. if (empty ($langhtml2pdf))
  48. {
  49. $langhtml2pdf = 'en';
  50. }
  51. switch ($langhtml2pdf)
  52. {
  53. case 'uk':
  54. $langhtml2pdf = 'ukr';
  55. break;
  56. case 'pt':
  57. $langhtml2pdf = 'pt_pt';
  58. break;
  59. case 'pt-br':
  60. $langhtml2pdf = 'pt_br';
  61. break;
  62. // Code here other noticed exceptions.
  63. }
  64. // Checking for availability of a corresponding language file.
  65. if (!file_exists(api_get_path(SYS_PATH).'main/inc/lib/html2pdf/langues/'.$langhtml2pdf.'.txt'))
  66. {
  67. // If there was no language file, use the english one.
  68. $langhtml2pdf = 'en';
  69. }
  70. ////
  71. //$script = "
  72. //var rep = app.response('Your name');
  73. //app.alert('Hello '+rep);
  74. //";
  75. $html2pdf = new HTML2PDF('P','A4',$langhtml2pdf, array(30,10,30,10));//array (margin left, margin top, margin right, margin bottom)
  76. //$html2pdf->pdf->IncludeJS($script);
  77. //$html2pdf->pdf->IncludeJS("print(true);");
  78. //$html2pdf->pdf->IncludeJS("app.alert('Generated by Dokeos to PDF');");
  79. //$html2pdf->pdf->SetProtection(array('print'), 'guest');//add a password sample: guest
  80. $html2pdf->pdf->SetAuthor('Wiki Dokeos');
  81. $html2pdf->pdf->SetTitle($titlePDF);
  82. $html2pdf->pdf->SetSubject('Exported from Dokeos Wiki');
  83. $html2pdf->pdf->SetKeywords('Dokeos Wiki');
  84. //$html2pdf->WriteHTML(utf8_decode($htmlbuffer));
  85. $html2pdf->WriteHTML($htmlbuffer);
  86. $html2pdf->Output($titlePDF.'.pdf', 'D');
  87. ?>