|
|
เอาจากกระทู้ 047979 นี้ครับมาปรับ ของคุณ chao ช่วยด้วยครับ PHP PDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ ผมเอาของคุณมาปรับแล้วไม่แสดงภาษาไทยเป็นภาษาต่างดาวครับ แล้วข้อมูล มันแสดงรายการ 2 รอบ ทำให้ข้อมูลคูณสองเลยครับ ขอคำแนะนำหน่อยหรือส่งรายละเอียดมาที่ [email protected] ขอบคุณครับ
ตามรายละเอียดนี้ครับ หรือผู้รู้ช่วยแนะนำหน่อยขอบคุณล่วงหน้าครับ
<?php
require('fpdf.php');
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Simple table
function BasicTable($header,$data)
{
//Header
$w=array(15,20,25,30,35,25,25);
//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(15,6,$eachResult["customer_id"],1,0,'C');
$this->Cell(20,6,$eachResult["cat_id"],1,0,'C');
$this->Cell(25,6,$eachResult["passcat_id"],1,0,'C');
$this->Cell(30,6 ,$eachResult["intial_name"],1,0,'C');
$this->Cell(35,6,$eachResult["name_p"],1,0,'C');
$this->Cell(25,6,$eachResult["lname_p"],1,0,'C');
$this->Cell(25,6,$eachResult["day_cus"],1,0,'C');
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(15,20,25,30,35,25,25);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
//$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(15,6,$eachResult["customer_id"],1,0,'C');
$this->Cell(20,6,$eachResult["cat_id"],1,0,'C');
$this->Cell(25,6,$eachResult["passcat_id"],1,0,'C');
$this->Cell(30,6 ,$eachResult["intial_name"],1,0,'C');
$this->Cell(35,6,$eachResult["name_p"],1,0,'C');
$this->Cell(25,6,$eachResult["lname_p"],1,0,'C');
$this->Cell(25,6,number_format($eachResult["day_cus"],2),1,0,'C');
$this->Ln();
}
//Closure line
$this->Cell(array_sum($w),0,'','T');
}
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(15,20,25,30,35,25,25);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'C',$fill);
$this->Cell($w[4],6,number_format($row[4]),'LR',0,'R',$fill);
$this->Cell($w[5],6,number_format($row[5]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('ÃËÑÊ','CAT ID','PASSWORD','¤Ó¹Ó˹éÒ','ª×èÍ','¹ÒÁÊ¡ØÅ','Çѹ·ÕèºÑ¹·Ö¡');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","admin123") or die("Error Connect to Database");
$objDB = mysql_select_db("db_hinet");
//mysql_query("set NAMES'UTF8'");// set ÍÑ¡¢ÃÐãËéà»ç¹ Utf8 à¾ÔèÁµÃ§¹ÕéàŤÃѺ ÃѺÃͧä´éªÑǤÃѺ
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT * FROM customer ";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
//$pdf->AddFont('angsana','','angsa.php');
//$pdf->AddFont('angsana','B','angsab.php');
//$pdf->AddFont('angsana','I','angsai.php');
//$pdf->AddFont('angsana','BI','angsaz.php');
$pdf->SetFont('angsana','',12);
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Image('http://localhost/hinet/images/logo5.gif',80,8,33);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
//*** Table 2 ***//
$pdf->AddPage();
$pdf->Image('http://localhost/hinet/images/logo5.gif',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);
//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('http://localhost/hinet/images/logo5.gif',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
<CENTER><TD>Report PDF. <a href="MyPDF/MyPDF.pdf" target='_parent'>Click here</a> to Download </TD></CENTER>
</body>
</html>
Tag : PHP
|
|
|
|
|
|
Date :
2010-09-16 02:02:24 |
By :
roykeane16 |
View :
2822 |
Reply :
1 |
|
|
|
|
|
|
|
|
|