You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
6.8 KiB

4 years ago
4 years ago
4 years ago
  1. <?php
  2. session_start();
  3. require "config.php";
  4. #$CONVERT_CMD = "/usr/bin/pdftk";
  5. require_once('TCPDF/tcpdf.php');
  6. class kaformPDF extends TCPDF {
  7. //Page header
  8. public function Header() {
  9. }
  10. // // Logo
  11. // $image_file = K_PATH_IMAGES.'logo_example.jpg';
  12. // $this->Image($image_file, 10, 10, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
  13. // // Set font
  14. // $this->SetFont('helvetica', 'B', 20);
  15. // // Title
  16. // $this->Cell(0, 15, '<< TCPDF Example 003 >>', 0, false, 'C', 0, '', 0, false, 'M', 'M');
  17. // }
  18. //
  19. // // Page footer
  20. public function Footer() {
  21. }
  22. // // Position at 15 mm from bottom
  23. // $this->SetY(-15);
  24. // // Set font
  25. // $this->SetFont('helvetica', 'I', 8);
  26. // // Page number
  27. // $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  28. // }
  29. // }
  30. //
  31. };
  32. function mkFrontPDF(){
  33. // create new PDF document
  34. $pdf = new kaformPDF(
  35. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  36. true, 'UTF-8', false);
  37. // set document information
  38. /* $pdf->SetCreator(PDF_CREATOR);
  39. $pdf->SetAuthor('Nicola Asuni');
  40. $pdf->SetTitle('TCPDF Example 001');
  41. $pdf->SetSubject('TCPDF Tutorial');
  42. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  43. */
  44. // set default header data
  45. // $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,
  46. // PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING,
  47. // array(0,64,255), array(0,64,128));
  48. // $pdf->setFooterData(array(0,64,0), array(0,64,128));
  49. // set header and footer fonts
  50. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  51. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  52. // set default monospaced font
  53. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  54. // set margins
  55. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  56. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  57. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  58. // set auto page breaks
  59. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  60. // set image scale factor
  61. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  62. // set some language-dependent strings (optional)
  63. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  64. require_once(dirname(__FILE__).'/lang/eng.php');
  65. $pdf->setLanguageArray($l);
  66. }
  67. // ---------------------------------------------------------
  68. // set default font subsetting mode
  69. $pdf->setFontSubsetting(true);
  70. // Set font
  71. // dejavusans is a UTF-8 Unicode font, if you only need to
  72. // print standard ASCII chars, you can use core fonts like
  73. // helvetica or times to reduce file size.
  74. $pdf->SetFont('dejavusans', '', 14, '', true);
  75. // Add a page
  76. // This method has several options, check the source code
  77. // documentation for more information.
  78. $pdf->AddPage('P');
  79. // set text shadow effect
  80. $pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2,
  81. 'depth_h'=>0.2, 'color'=>array(196,196,196),
  82. 'opacity'=>1, 'blend_mode'=>'Normal'));
  83. // calculate the overall summary
  84. $sum = calcSum();
  85. // Set some content to print
  86. $html =
  87. <<<EOD
  88. <h1>Kostenerstattungsantrag &uuml;ber $sum EUR</h1>
  89. <p><b>Projekt: $_POST[project]</b></p>
  90. <p>WMDE Ansprechpartner: $_POST[wmdecontact]</p>
  91. <hr>
  92. <p>
  93. &nbsp;
  94. <br>
  95. Name: $_POST[realname]<br>
  96. E-Mail: $_POST[email]<br>
  97. Telefon: $_POST[phone]
  98. </p>
  99. <hr>
  100. EOD;
  101. // Print text using writeHTMLCell()
  102. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  103. // ---------------------------------------------------------
  104. $tn = tempnam("/tmp","kaform");
  105. // Close and output PDF document
  106. // This method has several options, check the source code
  107. // documentation for more information.
  108. $pdf->Output($tn, 'F');
  109. return $tn;
  110. }
  111. function mkSnippedPdf($key){
  112. $pageLayout = array(210,70);
  113. // create new PDF document
  114. # $pdf = new kaformPDF(
  115. # PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT,
  116. # true, 'UTF-8', false);
  117. $pdf = new kaformPDF(
  118. PDF_PAGE_ORIENTATION, PDF_UNIT, $pageLayout /*PDF_PAGE_FORMAT*/,
  119. true, 'UTF-8', false);
  120. $pdf->AddPage('L');
  121. $pos = array_search($key,array_keys($_POST['desc']))+1;
  122. echo "<br>Make Snipped for $key -> $pos<br>";
  123. # $mydesk = $_POST[desc][$key];
  124. #
  125. $amount = $_POST['amount'][$key];
  126. $desc = $_POST['desc'][$key];
  127. $html =
  128. <<<EOD
  129. <h1>Posi. $pos</h1>
  130. <p>$desc</p><br>
  131. <p>$amount EUR</p><br>
  132. EOD;
  133. // Print text using writeHTMLCell()
  134. $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
  135. $tn = tempnam("/tmp","kaform");
  136. // Close and output PDF document
  137. // This method has several options, check the source code
  138. // documentation for more information.
  139. $pdf->Output("$tn", 'F');
  140. return $tn;
  141. }
  142. //var_dump($_POST);
  143. function convert($row) {
  144. $r = array();
  145. foreach ($_SESSION['files'] as $filename => $file){
  146. if ($file['row'] != $row)
  147. continue;
  148. $tn = tempnam("/tmp","kaform");
  149. file_put_contents("$tn",$file['content']);
  150. array_push($r,"$tn");
  151. }
  152. return $r;
  153. }
  154. function calcSum(){
  155. $sum =0;
  156. if (!isset($_POST['amount'])) {
  157. echo "wrong parameters";
  158. die;
  159. }
  160. foreach ($_POST['amount'] as $val){
  161. var_dump($val);
  162. $sum += floatval(str_replace(",",".",$val));
  163. }
  164. return $sum;
  165. }
  166. $pdfs = array();
  167. // Applicatoin starts here
  168. $p = mkFrontPDF();
  169. array_push($pdfs,$p);
  170. foreach ($_POST['desc'] as $key => $val) {
  171. echo "DREESK KEY VAL $key --> $val<br>";
  172. $p = mkSnippedPDF($key);
  173. array_push($pdfs,$p);
  174. $pr = convert($key);
  175. $pdfs = array_merge($pdfs,$pr);
  176. }
  177. var_dump($pdfs);
  178. $cmd = "$CONVERT_CMD";
  179. foreach ($pdfs as $filename){
  180. $cmd .= " $filename";
  181. }
  182. $cmd .= " cat output /tmp/result.pdf";
  183. exec ($cmd);
  184. echo "CMD: $cmd<br>";