2 Replies - 889 Views - Last Post: 20 December 2011 - 06:12 PM Rate Topic: -----

#1 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Printing Data in PDF

Posted 20 December 2011 - 05:37 PM

I am trying to generate a pdf file that will display the searched data performed in the current page. In the current page, the searched data is displayed in table form, how can I make a button to generate the searched data in pdf from the current page? Please some one help me,I've tried using fpdf but only manage to generate a blank pdf. I have no idea how to print the data in the current page. Help please.
Is This A Good Question/Topic? 0
  • +

Replies To: Printing Data in PDF

#2 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,297
  • Joined: 22-October 08

Re: Printing Data in PDF

Posted 20 December 2011 - 05:54 PM

What have you tried? Can you supply some source code? You need to give to get :)
Was This Post Helpful? 0
  • +
  • -

#3 nielsen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 17-July 11

Re: Printing Data in PDF

Posted 20 December 2011 - 06:12 PM

This is the page will generate the table that will display the data. I have no problem to display the data searched. The button "cetak" will generate a pdf file which will displayed the searched data which I am having problem in displaying.

 <body>
   
    
    <form method="post" action="searchschoolsthis2.php">
    <input type="hidden" name="submitted" value="true" />
    
    <label><span class="style2">Pilih Kategori:</span>
    <span class="style1">
    <select name="category">
      <option value="negeri">State</option>
      <option value="daerah">County</option>
      <option value="kod_sekolah">Code</option>
    </select>
     </span></label>
     
     <span class="style1">
     <span class="style2">Type Criteria
     <label>:</label>
     </span>
     <label>
     <input type="text" name="criteria" onkeyup="this.value = this.value.toUpperCase();"/>
     </label>
     <input type="submit" value="Cari" />
     </span>
          
     </form>
     
         
     <form action="cetakpdf.php" method="post" name="cetak" target="_blank" id="cetak">
              <input type="submit" name="cetak" id="cetak" value="Cetak" />
        
              
    
    </form>
    
        <table width='100%' color='black' id='header'>
       <thead>
        <tr>
          <td width="40%" scope="col"><div align="center"><span class="style2">Code</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Name</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">PTJ</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Server</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">PC</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">NB</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Mono Laser</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Color Laser</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Dot Matrix</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">LCD</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">LAN</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Cost</span></div></td> 
          <td width="40%" scope="col"><div align="center"><span class="style2">Paid</span></div></td> 
          <td width="50%" scope="col"><div align="center"><span class="style2">Not Paid</span></div></td> 
        </tr>
      </thead>
        </table>
        
    
        
    <?php
	
	if(isset($_POST['submitted'])){
	
	include('connect.php');
	$category=$_POST['category'];
	$criteria=$_POST['criteria'];
	$query="SELECT * FROM schools WHERE $category = '$criteria'";
	$result=mysqli_query($dbcon,$query) or die('error getting data');
		
	
		
	echo "<table width='120%' border='2' color='black' id='header'>";
	
	
	
	while ($row = mysqli_fetch_array($result,MYSQL_ASSOC)){
	
		
	echo"<tr><td>";
	
	echo $row['code'];
	
	echo"</td><td>";	
		
	echo $row['name'];
	echo"</td><td>";
	
	echo $row['ptj'];
	echo"</td><td>";
	
	echo $row['server'];
	echo"</td><td>";
	
	echo $row['pc'];
	echo"</td><td>";
	
	echo $row['nb'];
	echo"</td><td>";
	
	echo $row['mono_laser'];
	echo"</td><td>";
	
	echo $row['color_laser'];
	echo"</td><td>";
	
	echo $row['dot_matrix'];
	echo"</td><td>";
	
	echo $row['lcd'];
	echo"</td><td>";
	
	echo $row['lan'];
	echo"</td><td>";
	
	echo $row['cost'];
	echo"</td><td>";
	
	echo $row['paid'];
	echo"</td><td>";
	
	echo $row['not_paid'];
	//echo"</td><td  style='text-align:right'>";
			
	echo"</td></tr>";
	
	 
	}
			   	
	echo "</table>";
	
	}
	
	?>
   		  <tr>
            <td><form action="cetakpdf.php" method="post" name="cetak" target="_blank" id="cetak">
              
                          
            </form></td>
          </tr>


Below are the "cetakpdf.php". I have no idea how to display the searched data in the above code in pdf.
<?php
require('fpdf16/fpdf.php'); 


class PDF extends FPDF
{

function TableHeader(){
$this->SetFont('Arial','B','9');
$this->Cell('40','26','',0,0);
$this->Cell('110','5.2','School Inventory',0,2,C);

}


function BhgB(){
$this->SetFont('Times','B',8);
 //Colors of frame, background and text
    $this->SetDrawColor(0,80,180);
    $this->SetFillColor(200,220,255);
    $this->SetTextColor(1,1,1);
$this->Cell('25','6','Code',1,0,C);
$this->Cell('50','6','Name',1,0,C);
$this->Cell('20','6','PTJ',1,0,C);
$this->Cell('20','6','Server',1,0,C);
$this->Cell('15','6','PC',1,0,C);
$this->Cell('15','6','NB',1,0,C);
$this->Cell('15','6','Mono Laser',1,0,C);
$this->Cell('15','6','Color Laser',1,0,C);
$this->Cell('15','6','Dot Matrix',1,0,C);
$this->Cell('15','6','LCD',1,0,C);
$this->Cell('15','6','LAN',1,0,C);
$this->Cell('15','6','Cost',1,0,C);
$this->Cell('15','6','Paid',1,0,C);
$this->Cell('15','6','Not Paid',1,0,C);
}
}
$pdf=new PDF('P','mm','A3');
$pdf->SetMargins('19','19','19');
$pdf->AddPage();
$pdf->TableHeader();
$pdf->Ln();
$pdf->Ln();
$pdf->Ln();
$pdf->BhgB();
$pdf->Output();



?>



I hope anyone can guide me in doing this because I am new in php :(
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1