|
 |
|
PDF ภาษาไทยไม่ได้อ่าาาาา ช่วยหน่อยๆๆ ไม่ได้หลายวันแล้ว |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
require('fpdf/fpdf.php');
include("fpdf/font/helvetica.php");
class PDF extends FPDF
{
//convert thai
function conv($string) {
return iconv('UTF-8', 'TIS-620', $string);
}
//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(30,30,55,25,20,30);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620',$header[$i]),1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(30,6,$eachResult["Number"],1);
$this->Cell(30,6,$eachResult["FirstName"],1);
$this->Cell(55,6,$eachResult["LastName"],1);
$this->Cell(25,6,$eachResult["type"],1,0,'C');
$this->Cell(20,6,$eachResult["etc"],1);
$this->Cell(30,6,$eachResult["date"],1);
//$this->Cell(20,6,$eachResult["Budget"],1);
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(30,30,55,25,20,30);
//$w=array(20,30,55,25,25,45);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620',$header[$i]),1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(30,6,$eachResult["Number"],1);
$this->Cell(30,6,$eachResult["FirstName"],1);
$this->Cell(55,6,$eachResult["LastName"],1);
$this->Cell(25,6,$eachResult["type"],1,0,'C');
$this->Cell(20,6,$eachResult["etc"],1,0,'R');
$this->Cell(30,6,$eachResult["date"],1,0,'R');
//$this->Cell(25,6,number_format($eachResult["Budget"],2),1,0,'R');
$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(20,30,55,25,25);
for($i=0;$i<count($header);$i++)
//$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620',$header[$i]),1,0,'C');
$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,$row[4],'LR',0,'R',$fill);
$this->Cell($w[5],6,$row[5],'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('ลำดับที่','ชื่อ','ชื่อ-สกุล','ห้อง','ชั้น','00');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("personal");
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT * FROM data2 where date = '2011-09-13'";
$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->Cell( 80 , 6 , $pdf->conv("แบบฟอร์มการทำประกันภัย") , '0','0','C');
$pdf->SetFont('Arial','',10);
//$pdf->AddFont('Angsana','','angsa.php');
//$pdf->SetFont('AngsanaNew','',14);
$pdf->SetFont('Arial', 'B', 16);
$pdf->Text( 15 , 70 , $pdf->conv('ชื่อโครงการ '));
//*** Table 1 ***//
$pdf->AddPage();
$pdf->Cell(0,6,$pdf->conv("รายชื่อบุคลากรไม่มาประจำวัน 0000000000"),'0','1','C');
//$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->BasicTable($header,$resultData);
//*** Table 2 ***//
$pdf->AddPage();
//$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->ImprovedTable($header,$resultData);
//*** Table 3 ***//
$pdf->AddPage();
//$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output();
//$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>

ทำไงก็ไม่ได้ ช่วยดูให้หน่อยย หาจากหลายกระทู้แล้ววว T_T
Tag : PHP

|
|
 |
 |
 |
 |
Date :
2011-09-27 13:21:24 |
By :
new php |
View :
1966 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
define('FPDF_FONTPATH','fpdf_fontThai/');
require('fpdf.php');
$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','B',24);//ตัวอย่างการเรียกใช้
|
 |
 |
 |
 |
Date :
2011-09-27 13:33:54 |
By :
Professer |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เซฟ encodeing เป็น ANSI รึเปล่าครับ
|
 |
 |
 |
 |
Date :
2011-09-27 13:34:58 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เซฟ encodeing เป็น ANSI รึเปล่าครับ // ตรงไหนอ่ะครับ ไม่รู้เรื่องจริงๆ
ส่วนของคุณ Mr. อีฟ ทำแล้ว ขึ้น error สงสัยใส่ไม่ถูกที ขอเวลาทำความเข้าใจ แปป
ขอบคุณครับ ทั้งสองคน ^^
|
 |
 |
 |
 |
Date :
2011-09-27 13:48:42 |
By :
new php |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปิดไฟล์ด้วยโปรแกรมEditPlus แล้ว save as ตรง encodeing เลือกเป็น ANSI
แล้วได้ add font ไทยยังครับ ใน fpdf น่ะ
|
 |
 |
 |
 |
Date :
2011-09-27 15:40:42 |
By :
avsqlz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|