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.

240 lines
6.7 KiB

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