export_html2pdf.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. echo $contentPDF;
  29. $htmlbuffer=ob_get_contents();// Store Output-Buffer in one variable
  30. ob_end_clean();// delete Output-Buffer
  31. /////bridge to dokeos lang
  32. @ $langhtml2pdf = Database :: get_language_isocode($language_interface);
  33. // Some code translations are needed.
  34. $langhtml2pdf = strtolower(str_replace('_', '-', $langhtml2pdf));
  35. if (empty ($langhtml2pdf))
  36. {
  37. $langhtml2pdf = 'en';
  38. }
  39. switch ($langhtml2pdf)
  40. {
  41. case 'uk':
  42. $langhtml2pdf = 'ukr';
  43. break;
  44. case 'pt':
  45. $langhtml2pdf = 'pt_pt';
  46. break;
  47. case 'pt-br':
  48. $langhtml2pdf = 'pt_br';
  49. break;
  50. // Code here other noticed exceptions.
  51. }
  52. // Checking for availability of a corresponding language file.
  53. if (!file_exists(api_get_path(SYS_PATH).'main/inc/lib/html2pdf/langues/'.$langhtml2pdf.'.txt'))
  54. {
  55. // If there was no language file, use the english one.
  56. $langhtml2pdf = 'en';
  57. }
  58. ////
  59. //$script = "
  60. //var rep = app.response('Your name');
  61. //app.alert('Hello '+rep);
  62. //";
  63. $html2pdf = new HTML2PDF('P','A4',$langhtml2pdf, array(30,25,30,25));//array (margin left, margin top, margin right, margin bottom)
  64. $html2pdf->pdf->SetMyFooter( 'page','','','' );//page, date, time, form
  65. $html2pdf->pdf->SetDisplayMode('real');
  66. //$html2pdf->pdf->IncludeJS($script);
  67. //$html2pdf->pdf->IncludeJS("print(true);");
  68. //$html2pdf->pdf->IncludeJS("app.alert('Generated by Dokeos to PDF');");
  69. //$html2pdf->pdf->SetProtection(array('print'), 'guest');//add a password sample: guest
  70. $html2pdf->pdf->SetAuthor('Wiki Dokeos');
  71. $html2pdf->pdf->SetTitle($titlePDF);
  72. $html2pdf->pdf->SetSubject('Exported from Dokeos Wiki');
  73. $html2pdf->pdf->SetKeywords('Dokeos Wiki');
  74. //$html2pdf->WriteHTML(utf8_decode($htmlbuffer));
  75. $html2pdf->WriteHTML($htmlbuffer);
  76. $html2pdf->Output($titlePDF.'.pdf', 'D');
  77. ?>