2013-04-24 198 views
1

我是新來的TCPDF PHP庫的PDF創建。我可以打印一張表的第一列,但無法打印剩下的一列。這裏是我的代碼TCPDF某些變量不在輸出文件中打印?

<html> 
<head> 
<title>Admit Card</title> 
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"> 
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script> 

<style> 
@media print { 
    @page { margin: 0; } 
    body { margin: 1.6cm; } 
} 
</style> 
<script type="text/javascript" src="library/jquery-1.8.3.js" > </script> 
<script type="text/javascript"> 

    function PrintElem(elem) 
    { 
     Popup($(elem).html()); 
    } 

    function Popup(data) 
    { 
     var mywindow = window.open('', 'admit', 'width=800'); 
     mywindow.document.write('<html><head><title></title>'); 
     /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />'); 
     mywindow.document.write('</head><body >'); 
     mywindow.document.write(data); 
     mywindow.document.write('</body></html>'); 

     mywindow.print(); 
     mywindow.close(); 

     return true; 
    } 

</script> </head> <body> 
<div id="mydiv"> 
<?php 
ob_start(); 
session_start(); 
require_once('tcpdf/config/lang/eng.php'); 
require_once('tcpdf/tcpdf.php'); 
//ob_start(); 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, 'ISO-8859-1', false); 
// set document information 
$pdf->SetCreator(PDF_CREATOR); 
$pdf->SetAuthor('Dummy Dummy'); 
$pdf->SetTitle('Dummy Dummy'); 
$pdf->SetSubject('Dummy Dummy'); 
$pdf->SetKeywords('Dummy Dummy'); 
// set default header data 
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' CIT Kokrajhar', PDF_HEADER_STRING); 

// set header and footer fonts 
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); 
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); 

// set default monospaced font 
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 

//set margins 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER); 
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER); 

//set auto page breaks 
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 

//set image scale factor 
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

//set some language-dependent strings 
$pdf->setLanguageArray($l); 

// set font 
$pdf->SetFont('dejavusans', '', 10); 

// add a page 
$pdf->AddPage(); 

$html=' 

<table class="table" border="1"> <tr> 
      <td>Sl. No.</td> 
      <td>Name &amp; Father Name</td> 
      <td>Nos.</td> 
      <td>Roll Number</td> 
      <td width="98">Photo</td> 
      <td>Signature</td> 
      <td>Remarks</td> 
     </tr> 
'; 
//$html = ob_start(); 
$pdf->writeHTML($html, true, false, true, false, ''); 

?> 
<?php 



// 
     $username='root'; 
     $password = ''; 
     $conn = new PDO('mysql:host=localhost;dbname=somedbname',$username, $password); 
if(isset($_GET['exam'])){ 
    try{ 
     $center=$_GET['center']; 
     $exam=$_GET['exam']; 


     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     $strquery="SELECT * FROM dummytable_2013 WHERE `centre1`='".$center."' AND `examtype` LIKE '".$exam."%' ORDER BY RIGHT(`roll_number`, 3) ASC"; 
     $stmt=$conn->prepare($strquery); 
     $stmt->execute(); 
     //$rs = $stmt -> get_result(); 
     $rows = $stmt -> fetchAll(); 
     $i=0; 
     //print_r($rows); 
     foreach($rows as $row){ 
      $i=$i+1; 
      $form_number=$row['form_number']; 
      $name=$row['name']; 
      $roll=$row['roll_number']; 
      $examtype=$row['examtype']; 
      $sex=strtoupper($row['sex']); 
      $dob = $row['dob']; 
      $category = $row['category']; 
      $countrycode = $row['nationality']; 
      $email = $row['email']; 
      $region = $row['region']; 
      $examcenter1 =$row['centre1']; 
      $examcenter2 = $row['centre2']; 
      $examcenter3 = $row['centre3']; 
      $fathersname = strtoupper($row['fathersname']); 
      $mothersname = strtoupper($row['mothersname']); 
      $paddress = strtoupper($row['paddress']); 
      $caddress = strtoupper($row['caddress']); 
      $examname1 = $row['exam1']; 
      $year1 = $row['year1']; 
      $grade1 = $row['grade1']; 
      $percentage1 = $row['percentage1']; 
      $examname2 = $row['exam2']; 
      $year2 = $row['year2']; 
      $grade2 = $row['grade2']; 
      $percentage2 = $row['percentage2']; 
      $examname3 = $row['exam3']; 
      $year3 = $row['year3']; 
      $grade3 = $row['grade3']; 
      $percentage3 = $row['percentage3']; 
      $ddnumber = $row['ddnumber']; 
      $ddamount = $row['ddamount']; 
      $dddate = $row['dddate']; 
      $dddrawnat = $row['dddrawnat']; 
      $ddbranch = $row['ddbranch']; 
      $photo = $row['photoname']; 
      $substr="substr"; 
      if($i%7==0){ 
       $pdf->lastPage(); 

       // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
       // Print a table 

       // add a page 
       $pdf->AddPage(); 
       $html=<<<EOF 

       <tr> 
         <td>{$substr($roll, -3)}</td> 
         <td>Candidates Name: 
         Fathers Name: 
         </td> 
         <td>{$substr($roll, -3)}</td> 
         <td></td> 
         <td><img src="{$photo}" border="1" width="95" height="105"> 
</td> 
         <td> &nbsp;{$i}</td> 
         <td>{$form_number}</td> 
       </tr> 
EOF; 
//   $html = ob_start(); 
      $pdf->writeHTML($html, true, false, true, false, ''); 
      } 
      else{ 
      $html=<<<EOF 


     <tr> 
      <td>{$substr($roll, -3)}</td> 
      <td>Candidate&apos;s Name: 
      Fathers Name: 
      </td> 
      <td>{$substr($roll, -3)}</td> 
      <td>{$roll}</td> 
      <td><img src="{$photo}" border="1" width="95" height="105"> 
</td> 
      <td> &nbsp;{$i}</td> 
      <td>&nbsp;{$form_number}</td> 
     </tr> 

<?php 
EOF; 
//$html = ob_get_contents(); 
$pdf->writeHTML($html, true, false, true, false, ''); 
} 
     } 

        //function to send email 

    } 
    catch(PDOException $e) { 
     echo 'ERROR: ' . $e->getMessage(); 
    } 

// reset pointer to the last page 
$pdf->lastPage(); 

// --------------------------------------------------------- 

//Close and output PDF document 
$pdf->Output('rep/'.$exam.'.pdf', 'F'); 
ob_clean(); 
?> 
</table> 
</div> 
<center> 
<input value="Print The Sheet" class="btn btn-large btn-success" onclick="PrintElem('#mydiv')" type="button"> 
</center> 
</body> 
</html> 
<?php  
} 
else{ 
    echo 'session not set'; 
} 
?> 

結果在TCPDF輸出文件 只有先說的內容是MySQL連接之上。第一列變量是打印。結果低於

TCPDF Example Dummy Dummy 
by Nicola Asuni - Tecnick.com www.tcpdf.org 






Sl. No. Name & Father Name Nos. Roll Number Photo  Signature  Remarks 




001 





002 





003 





004 

回答

1

我想這個問題是由於適當的表列高度和寬度。在爲所有柱子設置適當的高度和寬度後,即在td字段中,其餘字段能夠獲得值。 如果沒有正確的表格屬性,Tcpdf不會打印值。現在問題已解決。