Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Formularz generująca PDF'a
theSzymek
post 29.01.2022, 17:22:53
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 29.01.2022

Ostrzeżenie: (0%)
-----


Hejka!

Widziałem w pracy jak szef się męczy przy pisaniu w wordzie każdego PDF'a z wyceną prac osobno i chciałem mu trochę pomóc.
Amatorsko lubiłem kodować, edytować style czy skrypty ale niestety okazało się, że to zadanie mnie przerasta lekko. Utknąłem.

Mianowicie zamysł jest taki ->
Interaktywny formularz z 5-cioma polami ( Liczba kolejna, Nr. Artykułu, Typ, Opis oraz Ilość ). Szef wpisuje w kola tekstowe dane, dodatkowo posiada przyciski "dodaj wers", "usuń wers", "generuj PDF".
O tyle o ile poradziłem sobie ładnie ze stroną główną interaktywnej tabelki o tyle kompletnie nie wiem jak się zabrać za generowanie PDF'a z danych które mam.

Stwierdziłem, że chcę to zrobić w PHPie (Udostępnię szefowi linka do strony gdzie to wrzucę), wiem, że pewnie jakiś python albo builder programu byłby łatwiejszy.
Czy jest ktoś w stanie mi pomóc? Podpowiedzieć, rozpocząć dalszy etap za mnie?

Chciałbym aby po kliknięciu "Generuj" nowy skrypt w php pobierał ilość wersów tabeli i tworzył odpowiadającą tabelę w nowym pliku PDF, to znaczy, żeby dane się przepisały do PDF'a.
Jak zrobię 4 wersy i wypełnię danymi żeby pobrało i zrobiło tak samo w PDF'ie.

Nie wiem którego rozszerzenia do tworzenia PDF'a użyć ani jak się za to zabrać. Dalej myślę, że jestem w stanie sam ogarnąć całego PDF,a do porządku.

Dziękuję za każdą pomoc i pozdrawiam.


Skrypt głównej strony który już mam:
  1. <form action="wynik.php" method="get">
  2. <p>
  3. <input style="height:50px;width:100px;font-size:20px;" type="button" value="Dodaj" onclick="addRowToTable();" />
  4. <input style="height:50px;width:100px;font-size:20px;" type="button" value="Usuń" onclick="removeRowFromTable();" />
  5. <input style="height:50px;width:100px;font-size:20px;" type="button" value="Generuj" onclick="validateRow(this.form);" />
  6. </p>
  7. <p>
  8. <input type="checkbox" id="chkValidate" /> Sprawdzanie
  9. <input type="checkbox" id="chkValidateOnKeyPress" checked="checked" /> Gdzie wpisuje
  10. <span id="spanOutput" style="margin-left:3px;border:1px solid #000;padding:3px;"> </span>
  11. </p>
  12. <table border="1" id="tabela" style="font-size:30px">
  13. <tr>
  14. <td>
  15. Np.
  16. </td>
  17. <td>
  18. Artykuł
  19. </td>
  20. <td>
  21. Typ
  22. </td>
  23. <td>
  24. Opis
  25. </td>
  26. <td>
  27. Ilość
  28. </td>
  29. </tr>
  30. <tr>
  31. <td>
  32. 1
  33. </td>
  34. <td>
  35. <input type="text" name="txt1Row1" id="txt1Row1" size="15" onkeypress="keyPressTest(event, this);" />
  36. </td>
  37. <td>
  38. <input type="text" name="txt2Row1" id="txt2Row1" size="40" onkeypress="keyPressTest(event, this);" />
  39. </td>
  40. <td>
  41. <input type="text" name="txt3Row1" id="txt3Row1" size="70" onkeypress="keyPressTest(event, this);" />
  42. </td>
  43. <td>
  44. <input type="number" name="txt4Row1" id="txt4Row1" size="15" onkeypress="keyPressTest(event, this);" />
  45. </td>
  46. </tr>
  47. </table>
  48. </form>
  49.  
  50. <script>
  51. function addRowToTable()
  52. {
  53. var tbl = document.getElementById('tabela');
  54. var lastRow = tbl.rows.length;
  55. var iteration = lastRow;
  56. var row = tbl.insertRow(lastRow);
  57.  
  58. // Pierwsza
  59. var cellLeft = row.insertCell(0);
  60. var textNode = document.createTextNode(iteration);
  61. cellLeft.appendChild(textNode);
  62. cellLeft.id = 'liczba' + iteration;
  63.  
  64. // Druga
  65. var cellRight = row.insertCell(1);
  66. var el = document.createElement('input');
  67. el.type = 'text';
  68. el.name = 'txt1Row' + iteration;
  69. el.id = 'txt1Row' + iteration;
  70. el.size = 15;
  71.  
  72. // Trzecia
  73. var cellRight1 = row.insertCell(1);
  74. var el1 = document.createElement('input');
  75. el1.type = 'text';
  76. el1.name = 'txt2Row' + iteration;
  77. el1.id = 'txt2Row' + iteration;
  78. el1.size = 40;
  79.  
  80. // Czwarta
  81. var cellRight2 = row.insertCell(1);
  82. var el2 = document.createElement('input');
  83. el2.type = 'text';
  84. el2.name = 'txt3Row' + iteration;
  85. el2.id = 'txt3Row' + iteration;
  86. el2.size = 70;
  87.  
  88. // Piata
  89. var cellRight3 = row.insertCell(1);
  90. var el3 = document.createElement('input');
  91. el3.type = 'number';
  92. el3.name = 'txt4Row' + iteration;
  93. el3.id = 'txt4Row' + iteration;
  94. el3.size = 15;
  95.  
  96. el.onkeypress = keyPressTest;
  97. cellRight3.appendChild(el);
  98. cellRight2.appendChild(el1);
  99. cellRight1.appendChild(el2);
  100. cellRight.appendChild(el3);
  101. }
  102. function keyPressTest(e, obj)
  103. {
  104. var validateChkb = document.getElementById('chkValidateOnKeyPress');
  105. if (validateChkb.checked) {
  106. var displayObj = document.getElementById('spanOutput');
  107. var key;
  108. if(window.event) {
  109. key = window.event.keyCode;
  110. }
  111. else if(e.which) {
  112. key = e.which;
  113. }
  114. var objId;
  115. if (obj != null) {
  116. objId = obj.id;
  117. } else {
  118. objId = this.id;
  119. }
  120. displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
  121. }
  122. }
  123. function removeRowFromTable()
  124. {
  125. var tbl = document.getElementById('tabela');
  126. var lastRow = tbl.rows.length;
  127. if (lastRow > 2) tbl.deleteRow(lastRow - 1);
  128. }
  129. function openInNewWindow(frm)
  130. {
  131. var aWindow = window.open('', 'TableAddRowNewWindow',
  132. 'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
  133. frm.target = 'TableAddRowNewWindow';
  134. frm.submit();
  135. }
  136. function validateRow(frm)
  137. {
  138. var chkb = document.getElementById('chkValidate');
  139. if (chkb.checked) {
  140. var tbl = document.getElementById('tabela');
  141. var lastRow = tbl.rows.length - 1;
  142. var i;
  143. for (i=1; i<=lastRow; i++) {
  144. var aRow = document.getElementById('txtRow' + i);
  145. if (aRow.value.length <= 0) {
  146. alert('Row ' + i + ' is empty');
  147. return;
  148. }
  149. }
  150. }
  151. openInNewWindow(frm);
  152. }
  153. </script>
Go to the top of the page
+Quote Post
nospor
post 31.01.2022, 10:13:53
Post #2





Grupa: Moderatorzy
Postów: 36 440
Pomógł: 6290
Dołączył: 27.12.2004




Np. mPdf


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 30.03.2024 - 04:04