簡體   English   中英

TC PDF正在生成空白頁

[英]TC PDF is generating blank page

我對TCPDF非常陌生。 我正在嘗試從數據庫生成一些訪客通行證,並將其顯示/保存為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>';



?>

請幫助我找出錯誤的地方。

您應該取消注釋$pdf->Output('example_002.pdf', 'I') ,在主窗口中使用print和close 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函數將無法正常工作,然后生成空白頁。

確保將要發送到PDF的html有效,並且不會遺漏任何標簽和/或有任何錯誤。 嘗試先輸出HTML,然后看一切是否正常。

也嘗試使用簡單的小型有效html來測試TCPDF。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM