ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: utchara ที่ 29 ตุลาคม 2013, 10:02:17



หัวข้อ: เขียน PHP สร้งไฟล์ PDF แล้ว error ช่วยแนะนำทีค่ะ
เริ่มหัวข้อโดย: utchara ที่ 29 ตุลาคม 2013, 10:02:17
<?php

define('FPDF_FONTPATH','font_pdf/');
require('fpdf/fpdf.php');
include("idna_convert.class.php");
include ("inc_dbconnect.php");
class PDF extends FPDF
{

function Footer()
{      
    //footer
   $this->SetFont('CordiaNew','',12);
   $this->SetTextColor(0);
   $this->SetY(-15);
   $this->Cell(0,10,'ถนนรัชดาภิเษก ',0,1,'C');
   $this->Cell(0,0,'แขวงห้วยขวาง เขตห้วยขวาง กทม. 10310',0,0,'C');
   
}


function LoadData($file)
{
   //Read file lines
   $lines=file($file);
   $data=array();
   foreach($lines as $line)
      $data[]=explode(';',chop($line));
   return $data;
}

function BasicTable($header,$data)
{
   //Header
   $w=array(30,30,55,25,20,20,20);
   //Header
   for($i=0;$i<count($header);$i++)
      $this->Cell($w[$i],7,$header[$i],1,0,'C');
   $this->Ln();
   //Data
   foreach ($data as $eachResult)
   {
      $this->Cell(30,6,$eachResult["keywords_id"],1);
      $this->Cell(30,6,$eachResult["prop_id"],1);
      $this->Cell(55,6,$eachResult["keywords_topic"],1);
      $this->Cell(25,6,$eachResult["keywords_find"],1,0,'C');
      $this->Cell(20,6,$eachResult["keywords_cpc"],1);
      $this->Cell(20,6,$eachResult["keywords_remark"],1);
      $this->Cell(20,6,$eachResult["lastUpdate"],1);                   
      $this->Ln();
   }
}



}//end class


      $pdf = new PDF();
      $pdf->AddPage();
      $pdf->Remaining_Budget();   
      
      $header=array('keywords_id','prop_id','keywords_topic','keywords_find','keywords_cpc','keywords_remark','lastUpdate');
      //Data loading
      
      //*** Load MySQL Data ***//
      $strSQL = "SELECT * FROM keywords where prop_id='7' ";
      $objQuery = mysql_query($strSQL, $dbname);
      $resultData = array();
         
      for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
         $result = mysql_fetch_array($objQuery);
         array_push($resultData,$result);
      }
      
      
      $pdf->SetFont('Arial','',10);

      //*** Table 1 ***//
      $pdf->AddPage();
      $pdf->Ln(35);
      $pdf->SetFont('CordiaNew','',14);
      $pdf->BasicTable($header,$resultData);

      
      
      $path = "/home/keyword";
      $filename = "example_report.pdf";      
      $path_file = $path."/".$filename;

      $pdf->Output('$path_file', 'I');
   

?>


หน้าต่างแสดง error
FPDF error: Some data has already been output, can't send PDF file

ช่วยแนะนำด้วยนะคะ ขอบคุณค่ะ :P


หัวข้อ: Re: เขียน PHP สร้งไฟล์ PDF แล้ว error ช่วยแนะนำทีค่ะ
เริ่มหัวข้อโดย: smapan ที่ 29 ตุลาคม 2013, 10:16:42
http://www.thaicreate.com/php/forum/044028.html


หัวข้อ: Re: เขียน PHP สร้งไฟล์ PDF แล้ว error ช่วยแนะนำทีค่ะ
เริ่มหัวข้อโดย: adidog ที่ 29 ตุลาคม 2013, 10:20:49
ไม่เคยใช้ FPDF ใช้แต่ TCPDF ลองดูพวก encode ของไฟล์ครับ