2011-11-23 128 views
0

我對TCPDF很陌生。我試圖從數據庫中生成一些訪問者通行證並將它們顯示/保存爲PDF。但它正在製作空白頁。請幫幫我。我的完整代碼如下。TC PDF正在生成空白頁面

<?php require_once('db.php'); 
require_once('pdf.php'); 
require_once('tcpdf/config/lang/eng.php'); 
require_once('tcpdf/tcpdf.php'); 
// create new PDF document 

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

// set document information 
$pdf->SetCreator(PDF_CREATOR); 
$pdf->SetAuthor('Nicola Asuni'); 
$pdf->SetTitle('TCPDF Example 006'); 
$pdf->SetSubject('TCPDF Tutorial'); 
$pdf->SetKeywords('TCPDF, PDF, example, test, guide'); 

// set default header data 

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 

//set margins 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 

$pdf->setPrintHeader(false); 
$pdf->setPrintFooter(false); 

//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(); 
?> 
<?php 
function data($name, $data){ 
    $q=mysql_fetch_row(mysql_query("SELECT `$data` FROM page_setting WHERE setting_name='temp1'")); 
    return $q['0']; 
} 
?> 
<?php 
$name='temp1'; 
//echo "<div style='width:".data($name, "pg_width")."'>"; 
//$name=strip_tags($_POST['setting_name']); 
//$company=addslashes($_POST['company_name']); 
//$company_member=filter_var($_POST['totaluser'], FILTER_SANITIZE_NUMBER_INT); 
$r=mysql_query("SELECT name,company,country,name,country,pic FROM pass WHERE company=25"); 
//$dir=mkdir('temp_pass', 0777); 
$con="temp_pass/"; 
while($q=mysql_fetch_row($r)){ 
$myname=$q['0']; /// Name of the Person; 
$mycompany=$q['1']; 
$mycountry=$q['2']; 
$myemail=$q['3']; 
$myphone=$q['4']; 
$img="http://thirdeyenet.biz/".$q['5']; 

$fast= '<table border="0" align="left" width="'.data($name, "pg_width").'" height="'.data($name, "pg_height").'" style="border:#999999 1px solid; background:url("watermark/'.data($name, "watermark").') center no-repeat"> 
    <tr> 
    <td style=" background:#'.data($name, "bgcolor").' url('.data($name, "pg_bg_img").') no-repeat center;" width="'.data($name, "pg_width").'" height="'.data($name, "pg_height").'"><img src="bc/'.data($name,"bar").'.png" style="position:relative; '.data($name,"bc_position").'" align="absmiddle" /><div id="main" style="position:relative;margin-top:'.data($name, "pg_margin_top").'; margin-bottom:'.data($name, "pg_margin_bottom").'; margin-left:'.data($name, "pg_margin_left").'; margin-right:'.data($name, "pg_margin_right").'">'; 
//  <!-- Name will be here--> 
if(data($name, "name_font_visible")=="visible"){ 
$fnt= '<div align="left" style="position:relative; '.data($name, "name_position").' visibility:'.data($name, "name_font_visible").'; font-family:'.data($name, "name_font").'; color:'.data($name, "name_font_color").'; font-size:'.data($name, "name_font_size").'; font-style:'.data($name, "name_font_style").'">Name: '.$myname.'</div> 
     </div>'; 
     } 

//  <!-- Company Name will be here--> 

if(data($name, "company_font_visible")=="visible"){ 
$cmpny ='<div align="left" style="position:relative; '.data($name, "company_position").' visibility:'.data($name, "company_font_visible").'; font-family:'.data($name, "company_font").'; color:'.data($name, "company_font_color").'; font-size:'.data($name, "company_font_size").'; font-style:'.data($name, "company_font_style").'">Company: '.$mycompany.'</div>'; 
     } 

//  <!-- Country Name will be here--> 

    if(data($name, "country_font_visible")=="visible"){ 
$cntry= ' <div align="left" style="position:relative; '.data($name, "country_position").' visibility:'.data($name, "country_font_visible").'; font-family:'.data($name, "country_font").'; color:'.data($name, "country_font_color").'; font-size:'.data($name, "country_font_size").'; font-style:'.data($name, "country_font_style").'">Country: '.$mycountry.'</div>'; 
     } 

//  <!-- Email will be here--> 

if(data($name, "email_font_visible")=="visible"){ 
    $eml='<div align="left" style="position:relative; '.data($name, "email_position").' visibility:'.data($name, "email_font_visible").'; font-family:'.data($name, "email_font").'; color:'.data($name, "email_font_color").'; font-size:'.data($name, "email_font_size").'; font-style:'.data($name, "email_font_style").'">Email id: '.$myemail.'</div>'; 
     } 

//  <!-- Phone No will be here--> 

     if(data($name, "phone_font_visible")=="visible"){ 
    $phn= ' <div align="left" style="position:relative; '.data($name, "phone_position").' visibility:'.data($name, "phone_font_visible").'; font-family:'.data($name, "phone_font").'; color:'.data($name, "phone_font_color").'; font-size:'.data($name, "phone_font_size").'; font-style:'.data($name, "phone_font_style").'">Contact No: '.$myphone.'</div> 
     </div>'; 
     } 
    $last= '<div style="position:relative;'.data($name, "photo_position").'"><img src="'.$img.'" alt="" border="0" width="'.data($name, "phot_wd").'" height="'.data($name, "phot_hd").'" /></div><div style="margin-top:0px; margin-bottom:2px;"></div></td> 
    </tr> 
</table>'; 
$file=$fast.$fnt.$cmpny.$cntry.$eml.$phn.$last; 
/*$myFile = $con.mt_rand().".htm"; 
$fh = fopen($myFile, 'w'); 
fwrite($fh, $file); 
fclose($fh); 
*/ 
//$pdf->writeHTML($file, true, false, true, false, ''); 
//phptopdf_url($file, $con, mt_rand().".pdf"); 

//echo $file; 
//$file="<html><body><h1>hi</h1></body></html>"; 
$pdf->writeHTML($file, true, false, true, true); 

$pdf->lastPage(); 
//$pdf->Output('example_002.pdf', 'I'); 

} 



//echo "</div>"; 
echo '<script type="text/javascript"> 
     function PrintWindow() 
     {      
      window.print();    
      CheckWindowState(); 
     } 

     function CheckWindowState() 
     {   
      if(document.readyState=="complete") 
      { 
       window.close(); 
      } 
      else 
      {   
       setTimeout("CheckWindowState()", 1500) 
      } 
     }  

     PrintWindow(); 
</script>'; 



?> 

請幫我找到哪裏是錯..

+0

這個答案可能會幫助你。看看這個http://stackoverflow.com/a/39356741/5249203 – user5249203

回答

0

確保您的HTML這是會PDF是有效的,它不會錯過任何標記,或有任何錯誤。嘗試先輸出HTML,看看是否一切正常。

也嘗試outout簡單的小有效html來測試TCPDF。

0

您應該取消註釋$pdf->Output('example_002.pdf', 'I'),使用主窗口中的打印和關閉javascript功能。

例如:

echo '<script type="text/javascript" language="javascript"> 
    window.open("'.$this->url.'", "window_internal_name", '.$this->opc_ventana.'); 
    window.print(); 
    setTimeout("window.close();", 10000); </script>'; 
</pre> 

寫作副窗口的JavaScript功能將不起作用,並且然後空白頁被產生。