canvas-pdf.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. // Require composer autoload
  5. require_once __DIR__ . '/vendor/autoload.php';
  6. //Create an instance of the class in landscape:
  7. //x,left,x,top
  8. $mpdf = new mPDF('c', 'A4-L', '', 0,4,0,3);
  9. //Use a style sheet
  10. $stylesheet = file_get_contents('canvas-pdf.css');
  11. $mpdf->WriteHTML($stylesheet,1);
  12. //Write some HTML code:
  13. $title = $_POST['field_00'];//returns an array
  14. $field1Items= $_POST['field_01'];
  15. function fillItems($field_name){
  16. $item = '';
  17. $fieldItems= $_POST[$field_name];
  18. for($i=0; $i<count($fieldItems); $i++){
  19. $item .= '<ul class="items"><li>'.$fieldItems[$i].'</li></ul>';
  20. }
  21. return $item;
  22. }
  23. $html='<div class="wrapper">
  24. <div class="page_title">
  25. <div class="logo"><div class="logo-icon"></div>
  26. </div>
  27. <div class="project_title"><span>Project name: </span>'.$title[0].'</div>
  28. <div class="project_date"><span>Date: </span>'.$title[1].'</div>
  29. </div>
  30. <!-- end of .page_title -->
  31. <div class="row1">
  32. <div class=" card field_01"><h1>1. Individuals Affected</h1>'.fillItems("field_01").'
  33. <div class="field-icons"></div>
  34. </div>
  35. <div class="card field_02"><h1>2. Organisations and Groups Affected</h1>'.fillItems("field_02").'
  36. <div class="field-icons"></div>
  37. </div>
  38. <div class="card field_03"><h1>3. Products and Services provided</h1>'.fillItems("field_03").'
  39. <div class="field-icons"></div>
  40. </div>
  41. <div class="card field_04"><h1>4. Resources needed</h1>'.fillItems("field_04").'
  42. <div class="field-icons"></div>
  43. </div>
  44. <div class="card field_05"><h1>5. Changes in Behaviour</h1>'.fillItems("field_05").'
  45. <div class="field-icons"></div>
  46. </div>
  47. </div>
  48. <!-- end of Row2 -->
  49. <div class="row2">
  50. <div class=" card field_06"><h1>6. Changes in Relations</h1>'.fillItems("field_06").'
  51. <div class="field-icons"></div>
  52. </div>
  53. <div class="card field_07"><h1>7. Group Interests</h1>'.fillItems("field_07").'
  54. <div class="field-icons"></div>
  55. </div>
  56. <div class="card field_08"><h1>8. Public Sphere</h1>'.fillItems("field_08").'
  57. <div class="field-icons"></div>
  58. </div>
  59. <div class="card field_09"><h1>9. Impact of product or service failure</h1>'.fillItems("field_09").'
  60. <div class="field-icons"></div>
  61. </div>
  62. <div class="card field_10"><h1>10. Impact of use of resources</h1>'.fillItems("field_10").'
  63. <div class="field-icons"></div>
  64. </div>
  65. </div>
  66. <!-- end of Row2 -->
  67. <div class="row3">
  68. <div class=" card field_11"><h1>11. Social Conflicts</h1>'.fillItems("field_11").'
  69. <div class="field-icons"></div>
  70. </div>
  71. <div class="card field_12"><h1>12. Resolving ethical impacts</h1>'.fillItems("field_12").'
  72. <div class="field-icons"></div>
  73. </div>
  74. </div>
  75. <!-- end of Row3 -->
  76. <footer>
  77. <p><span>Ethics Canvas v1.7</span>|<span>&copy; ADAPT Center & Trinity College Dublin & Dublin City University, 2016</span>
  78. The Ethics Canvas is adapted from Alex Osterwalder’s Business Model Canvas. The Business Model Canvas is designed by: Business Model Foundry AG. This work is licensed under the Creative Commons Attribution-Share Alike 3.0 unported license. View a copy of this license at: https://creativecommons.org/licenses/by-sa/3.0/. View the original Business Model Canvas at https://strategyzer.com/canvas.
  79. <span class="contact-email">Contact us at: hello@ethicscanvas.org</span>
  80. </p>
  81. <div class="license-icons">
  82. <img src="../../icon/canvas-pdf-icons.png" alt="ethics-canvas-license-icon"/>
  83. </div>
  84. </footer>
  85. </div>';
  86. $mpdf->WriteHTML($html,2);
  87. if (isset($_POST['share-canvas'])) {
  88. // Share Canvas clicked: save on server
  89. $mpdf->Output('../saved-pdf/Ethics-Canvas.pdf','F');
  90. }
  91. else {
  92. // Export PDF clicked: download
  93. $mpdf->Output('Ethics-Canvas.pdf', 'D');
  94. }
  95. /* There are 3 ways to get the pdf:
  96. A. open the pdf in the users browser--> $mpdf->Output();
  97. B. force download the pdf to the users device --> $mpdf->Output('name-of-file.pdf', 'D');
  98. c. Save the pdf file on our server on the url that we say
  99. $mpdf->Output('my-directory/saved.pdf','F');
  100. */
  101. // A. Output a PDF file directly to the browser
  102. // $mpdf->Output();
  103. //B. Adding the 'D' parameter for download to user's device
  104. // $mpdf->Output('OnlineEthicsCanvas.pdf', 'D');
  105. //C. adding the 'F' to save the file
  106. //$mpdf->Output('../saved-pdf/Ethics-Canvas.pdf','F');
  107. // Close the window after creating the PDF
  108. echo "<script>window.close();</script>";
  109. ?>