serial number in pdf in html code using php

Solutions on MaxInterview for serial number in pdf in html code using php by the best coders in the world

showing results for - "serial number in pdf in html code using php"
Oisin
23 Aug 2017
1<?php  
2 function fetch_data()  
3 {  
4      $output = '';  
5      $conn = mysqli_connect("localhost", "root", "", "f1software"); 
6
7        //$site_cd=$_POST['site_cd'];
8
9      // $sql1 = "SELECT * FROM newsite";  
10      // $result1 = mysqli_query($conn, $sql1);  
11
12      $sql = "SELECT site_cd,item_cd,item_name,qty FROM newsite ORDER BY site_cd ASC";  
13      $result = mysqli_query($conn, $sql);  
14      while($row = mysqli_fetch_array($result))  
15      {       
16       
17      $output .= '<tr>  
18                          <td>1</td>  
19                          <td>'.$row["site_cd"].'</td>  
20                          <td>'.$row["item_cd"].'</td>  
21                          <td>'.$row["item_name"].'</td>  
22                          <td>'.$row["qty"].'</td>
23                     </tr>  
24                          ';  
25      }  
26 
27      return $output;  
28 }  
29 if(isset($_POST["generate_pdf"]))  
30 {  
31        
32      require_once('tcpdf/tcpdf.php');
33      $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  
34      $obj_pdf->SetCreator(PDF_CREATOR);  
35      
36      $obj_pdf->SetTitle("Quantity Availablity Report");  
37      $obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);  
38      $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));  
39      $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));  
40      $obj_pdf->SetDefaultMonospacedFont('helvetica');  
41      $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
42      $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);  
43      $obj_pdf->setPrintHeader(false);  
44      $obj_pdf->setPrintFooter(false);  
45      $obj_pdf->SetAutoPageBreak(TRUE, 10);  
46      $obj_pdf->SetFont('helvetica', '', 11);  
47      // $image = pdf_open_image_file($pdf, "jpeg", "https://www.iconfinder.com/data/icons/social-messaging-ui-color-shapes/128/document-circle-blue-512.png"); pdf_place_image($pdf, $image, 50, 650, 0.25);
48      $obj_pdf->Image('https://icon2.cleanpng.com/20180624/qoc/kisspng-computer-icons-desktop-wallpaper-5b2ff7a8c65759.3456430915298702488124.jpg',10,-1,70);
49      $obj_pdf->AddPage();  
50      $content = '';  
51      $content .= '  
52      <h4 align="center" >Neelam Construction</h4><br /> 
53      <table border="1" cellspacing="0" cellpadding="3">  
54           <tr>  
55                <th width="10%">Sr. No</th>
56                <th  width="22.5%">Site Code</th>  
57                <th width="22.5%">Item Code</th>  
58                <th width="22.5%">Item Name</th>  
59                <th width="22.5%">Total Qunatity</th>
60                
61           </tr>  
62      ';  
63      $content .= fetch_data();  
64      $content .= '</table>';  
65      $obj_pdf->writeHTML($content);  
66      $obj_pdf->Output('file.pdf', 'I');  
67
68 }  
69 ?>  
70 <!DOCTYPE html>  
71 <html>  
72      <head>  
73           <title>SoftAOX | Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</title>  
74           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />    
75          <style type="text/css">
76            body
77    {
78    counter-reset: Serial;           /* Set the Serial counter to 0 */
79    }
80            tr td:first-child:before
81    {
82  counter-increment: Serial;      /* Increment the Serial counter */
83  content: counter(Serial); /* Display the counter */
84    }
85          </style>
86
87      </head>  
88      <body>  
89           <br />
90           <div class="container">  
91                <h4 align="center" > Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</h4><br />  
92                <div class="table-responsive">  
93                	<div class="col-md-12" align="right">
94                     <form method="post">  
95                          <input type="submit" name="generate_pdf" class="btn btn-success" value="Generate PDF" />  
96                     </form>  
97                     </div>
98                     <br/>
99                     <br/>
100                     <table class="table table-bordered">  
101                          <tr>  
102                <th width="10%">Sr. No</th>              
103                <th width="22.5%">Site Code</th>  
104                <th width="22.5%">Item Code</th>  
105                <th width="22.5%">Item Name</th>  
106                <th width="22.5%">Total Qunatity</th>
107                 
108                
109                          </tr>  
110                     <?php  
111                     echo fetch_data();  
112                     ?>  
113                     </table>  
114                </div>  
115           </div>  
116      </body>  
117 </html>  
118