Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยด้วยครับ PHP PDF/FPDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ



 

ช่วยด้วยครับ PHP PDF/FPDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ

 



Topic : 047979



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์




ช่วยด้วยครับ PHP PDF - MySQL Export to PDF ภาษาไทยเป็นภาษาต่างดาวครับ
ผมลองตามกระทู้นี้ https://www.thaicreate.com/php/forum/044685.html แล้วก็ไม่ได้ครับ
ใส่ภาษาไทยก็ลองแล้วก็ยังไม่ได้ แต่ถ้าผมทดสอบภาษาไทยอย่างเดียวได้ครับ
แต่เมื่อดึงข้อมูลมาจากฐานข้อมูลภาษาไทยกลับเป็นภาษาต่างดาวแทน

ช่วยด้วยนะครับผมไม่รู้จะแก้ยังไงแล้วครับ

Code (PHP)
<?php
require('fpdf.php');
define('FPDF_FONTPATH','font/');
 
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["expose_id"],1,0,'C');
        $this->Cell(20,6,$eachResult["expose_product"],1,0,'C');
        $this->Cell(25,6,$eachResult["expose_number"],1,0,'C');
       $this->Cell(30,6 ,$eachResult["expose_name"],1,0,'C');
	   $this->Cell(35,6,$eachResult["expose_lastname"],1,0,'C');
	   $this->Cell(25,6,$eachResult["product_code"],1,0,'C');
	   $this->Cell(25,6,$eachResult["day"],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->Ln();
   //Data
 
    foreach ($data as $eachResult)
    {
        $this->Cell(15,6,$eachResult["expose_id"],1,0,'C');
        $this->Cell(20,6,$eachResult["expose_product"],1,0,'C');
        $this->Cell(25,6,$eachResult["expose_number"],1,0,'C');
       $this->Cell(30,6 ,$eachResult["expose_name"],1,0,'C');
	   $this->Cell(35,6,$eachResult["expose_lastname"],1,0,'C');
	   $this->Cell(25,6,$eachResult["product_code"],1,0,'C');
        $this->Cell(25,6,number_format($eachResult["day"],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('รหัส','สินค้า','จำนวนเบิก','ชื่อ','นามสกุล','รหัสสินค้า','วันที่เบิก');
//Data loading
 
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","344057","12345678") or die("Error Connect to Database");
$objDB = mysql_select_db("344057");
mysql_query("set NAMES'UTF8'");// set อักขระให้เป็น Utf8  เพิ่มตรงนี้เลยครับ   รับรองได้ชัวครับ
$strSQL = "SELECT * FROM expose ";
$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('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("MyPDF/MyPDF.pdf","F");
?>

PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>

ภาพข้อมูลภาษาไทยที่ดึงมาจากฐานข้อมูล



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-08-31 15:24:05 By : kritin View : 27232 Reply : 29
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Go to : ปัญหา การแปลง php เป็น pdf ภาษาไทย ซึ่ง ดึงข้อมูลมาจาก mysql รหัส ภาษา utf8 ไม่ได้ครับ


Go to : PHP PDF - MySQL Export to PDF






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 17:16:57 By : webmaster
 


 

No. 2

Guest


ยังทำไม่ได้เลยครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 21:30:33 By : Chao
 

 

No. 3

Guest


ตอนนี้ผมยังทำไม่ได้เลยครับ ผมยังเป็นมือใหม่อยู่เลยครับ

ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 21:33:32 By : Chao
 


 

No. 4

Guest


mysql_query("set NAMES'UTF8'");

เปลี่ยนเป็น

mysql_query("SET NAMES 'tis620' ");

มั๊ง
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-31 22:05:53 By : ิburn
 


 

No. 5



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์


จากที่ คุณ mr.win และ คุณ burn บอกมาแก้ได้แล้วครับ ขอบคุณมากครับ

แต่ติดอยูที่หัวข้อของตารางก็ยังเป็นภาษาต่างดาวอยู่ครับ
code หัวข้อตารางครับ
Code (PHP)
$header=array('รหัส','สินค้า','จำนวนเบิก','ชื่อ','นามสกุล','รหัสสินค้า','วันที่เบิก');

หัวข้อตารางเป็นภาษาต่างดาว


ประวัติการแก้ไข
2010-09-01 01:32:48
2010-09-01 01:34:37
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-01 01:32:13 By : kritin
 


 

No. 6



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

น่าจะวิธีเดียวกันครับ ใช้ function iconv
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-01 06:19:35 By : webmaster
 


 

No. 7



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์


ยังไม่ได้เลยครับผมลองทำหมดแล้วครับ รบกวนช่วยที่นะครับ

ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-01 11:44:07 By : kritin
 


 

No. 8



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
$this->Cell($w[$i],7,$header[$i],1,0,'C');


ตรงนี้น่ะครับ


Code (PHP)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');



ลองดูครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-03 17:39:39 By : webmaster
 


 

No. 9



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 8 เขียนโดย : webmaster เมื่อวันที่ 2010-09-03 17:39:39
รายละเอียดของการตอบ ::
ทำได้แล้วครับ ขอบคุณ คุณ mr.win มากครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-05 13:19:14 By : kritin
 


 

No. 10



โพสกระทู้ ( 9 )
บทความ ( 0 )



สถานะออฟไลน์


ผมเอาของคุณมาปรับแล้วไม่แสดงภาษาไทยเป็นภาษาต่างดาวครับ แล้วข้อมูล มันแสดงรายการ 2 รอบ ทำให้ข้อมูลคูณสองเลยครับ ขอคำแนะนำหน่อยหรือส่งรายละเอียดมาที่ [email protected] ขอบคุณครับ
ตามรายละเอียดนี้ครับ หรือผู้รู้ช่วยแนะนำหน่อยขอบคุณล่วงหน้าครับ


Code (PHP)
<?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>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-16 01:47:00 By : roykeane16
 


 

No. 11

Guest


ตอบความคิดเห็นที่ : 9 เขียนโดย : kritin เมื่อวันที่ 2010-09-05 13:19:14
รายละเอียดของการตอบ ::
... รบกวนคุณ chao ช่วยแสดง code เต็ม ๆ ให้หน่อยสิครับ ผมมือใหม่ยังแก้ปัญหาภาษาไทยไม่ได้เลยครับ (ตอนสร้าง database ระบุให้connection collation เป็น tis620_thai_ci ไปก่อนแล้วลงข้อมูลไว้เยอะเลยครับ).......

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-21 12:38:54 By : ken
 


 

No. 12

Guest


มันบอกว่า FPDF error: Undefined font: angsana
ทั้งที่ผมก็โหลด font มาลงแล้วมันแก้ยังไงหรอคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-19 22:09:13 By : finder
 


 

No. 13

Guest



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-07-28 17:52:50 By : sdfdf
 


 

No. 14



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Quote:
FPDF error: Undefined font: angsana


Error ตามนี้ครับ Go to : fpdf ไม่เป็นไทยครับช่วยหน่อย...FPDF error: Undefined font: angsana ..............
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-07-28 21:54:59 By : webmaster
 


 

No. 15

Guest


Thankมากๆๆๆๆคร่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-02-15 20:36:10 By : kimlung
 


 

No. 16



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook



Go to : PHP กับ PDF ภาษาไทย พิมพ์ข้อความบนเอกสาร PDF ภาษาไทย ด้วย FPDF
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-04-02 13:31:50 By : webmaster
 


 

No. 17

Guest


ตอบความคิดเห็นที่ : 5 เขียนโดย : kritin เมื่อวันที่ 2010-09-01 01:32:13
รายละเอียดของการตอบ ::
รบกวนคุณ Chao แสดง code เต็มๆที่ได้ผลแล้วหน่อยค่ะ ติดปัญหาตรงหัวข้อตารางเป็นภาษาต่างดาวเหมือนกันค่ะ รบกวนด้วยนะค่ะ ขอบคุณค่ะ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-05-18 14:59:30 By : Eye
 


 

No. 18

Guest


ค.ห. 5 ลองใส่ไปต้นไฟล์ก่อน tag php นะครับ ถ้าไม่ได้ก็ลองแก้ตรง charset เป็นตัวอื่น

<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-07 00:22:56 By : golf66
 


 

No. 19

Guest


คือว่า อยากได้ code ที่ไม่ต้องดาวน์โหลดอ่ะค่ะ คลิกแล้ว ขึ้นมาให้ปริ๊น เลยได้มั้ยคะ สามารถดูได้ที่เว็บไหนช่วยทีค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-16 10:25:07 By : เชอรี่
 


 

No. 20



โพสกระทู้ ( 5 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ขอไฟล์ที่สมบูรณ์แล้ว ดูเป็นตัวอย่างได้มั้ยครับผม ตอนนี้ติดส่วนนี้เหมือนกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-15 17:10:05 By : ron_pro
 


 

No. 21



โพสกระทู้ ( 22 )
บทความ ( 0 )



สถานะออฟไลน์


ไฟล์สมบูรณ์ครับ................ลองไปใส่ชื่อใน Table เป็นภาษาไทยดูครับ....เช่น สมชาย, สมหญิง ประมาณนี้ครับ..ดึงจาก Database เป็นไทยแน่นอนครับ...

เอามาแก้จากบทความนี่ครับ..https://www.thaicreate.com/php/php-pdf-mysql-export-pdf.html

Code (JavaScript)
<?php
define('FPDF_FONTPATH','font/');
require('fpdf.php');
$objConnect = mysql_connect("localhost","root","oce2012") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
@mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM customer";
$objQuery = mysql_query($strSQL);




class PDF extends FPDF
{



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,20);
	//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', 'cp874', $header[$i]),1,0,'C');
	$this->Ln();
	//Data
	foreach ($data as $eachResult) 
	{
		$this->Cell(30,6,$eachResult["CustomerID"],1);
		//$this->Cell(30,6,$eachResult["Name"],1);
		$this->Cell(30,6,iconv('UTF-8','cp874',$eachResult["Name"]),1);
		$this->Cell(55,6,$eachResult["Email"],1);
		$this->Cell(25,6,$eachResult["CountryCode"],1,0,'C');
		$this->Cell(20,6,$eachResult["Budget"],1);
		$this->Cell(20,6,$eachResult["Budget"],1);
		$this->Ln();
	}
}

//Better table
function ImprovedTable($header,$data)
{
	//Column widths
	$w=array(20,30,55,25,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', 'cp874', $header[$i]),1,0,'C');
	$this->Ln();
	//Data

	foreach ($data as $eachResult) 
	{
		$this->Cell(20,6,$eachResult["CustomerID"],1 );
		$this->Cell(30,6,$eachResult["Name"],1);
		$this->Cell(55,6,$eachResult["Email"],1);
		$this->Cell(25,6,$eachResult["CountryCode"],1,0,'C');
		$this->Cell(25,6,number_format($eachResult["Budget"],2),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,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', 'cp874', $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,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('รหัส','ชื่อ','Email','Country Code','Budget','Used');
//Data loading

//*** Load MySQL Data ***//

//require("ThaiPDF.class.php");

$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);
//$pdf->SetFont('Arial','',10);



//*** Table 1 ***//
$pdf->AddPage();
$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();
?>




ประวัติการแก้ไข
2012-09-24 12:35:05
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-24 12:30:34 By : dongjar
 


 

No. 22

Guest


ขอบคุณครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-09 00:23:46 By : jira
 


 

No. 23



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์


include(font/angsa.php) [fpdf.include]: failed to open stream: No such file or directory in

file angsa.php ทำยังไงครับไปเอาที่ไหนหรือครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-18 09:42:06 By : koopper2011
 


 

No. 24



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์


ขอบคุณ คุณ mr.win
ติดเหมือนกันแต่พอทำตามก็ออกแล้วค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-11-29 16:23:27 By : TKMaruko
 


 

No. 25



โพสกระทู้ ( 1 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis-620">
<title>ThaiCreate.Com PHP PDF</title>
</head>
<body>
ขอความช่วยเหลือด่วนครับ เป็นภาษาต่างดาวครับ ด่วนครับ ขอบคุณครับ
<?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(30,30,55,25,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["nt"],1);
		$this->Cell(30,6,$eachResult["fname"],1);
		$this->Cell(55,6,$eachResult["lname"],1);
		$this->Cell(25,6,$eachResult["phone"],1,0,'C');
 
		$this->Ln();
	}
}

//Better table
function ImprovedTable($header,$data)
{
	//Column widths
	$w=array(20,30,55,25,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(20,6,$eachResult["nt"],1);
		$this->Cell(30,6,$eachResult["fname"],1);
		$this->Cell(55,6,$eachResult["lname"],1);
		$this->Cell(25,6,$eachResult["phone"],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(20,30,55,25,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->Ln();
		$fill=!$fill;
	}
	$this->Cell(array_sum($w),0,'','T');
	$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C');

}
}

$pdf=new PDF();
//Column titles
$header=array('คำนำ','ชื่อ','นามสกุล','เบอร์โทร');
//Data loading

//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","6008") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "SELECT * FROM tb_teacher";
$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->SetFont('Arial','',10);

//*** Table 1 ***//
$pdf->AddPage();
$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("MyPDF/MyPDF.pdf","F");
?>

PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-07-25 10:58:31 By : supoj_f
 


 

No. 26

Guest


ขอบคุณ คุณ mr.win มากๆค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-23 22:50:55 By : aioonruk
 


 

No. 27

Guest


ขอตอบนะครับ

สร้าง file insert ข้อมูลเข้า mysql เป็น ansi ทั่วไปครับ

ใน file ให้เพิ่มบรรทัด

mysql_query("SET NAMES tis620"); // เพิ่มส่วนนี้ก่อนเข้า insert


if (!$result=mysql_query($query)){

echo '<font color=red>error: '.mysql_error().'<br>line: '.__LINE__.'<br>file: '.__FILE__."<br></font>";

}


// mysql data base กำหนด table หรือ file เป็น utf8_general_ci

หลังจากนั้น insert ข้อมูลปกติ

ส่วนการแสดงผล
ของ pdf ซึ่ง file กำหนดเป็น utf-8
// edit plus save as utf-8

แล้วเปิดการเชื่อมต่อ

$link=mysql_connect($dbhost,$dbuser,$dbpasswd); // เชื่อมต่อ Server
mysql_select_db($dbname); // ติดต่อฐานข้อมูล

mysql_query("set character set utf8"); // กำหนดค่า character set ที่จะใช้แสดงผล

เป็นอันเสร็จครับ

สรุปคือ mysql ต้องกำหนดเป็น utf-8
ก่อน insert ข้อมูลเราก็แปลงเป็น tis-620 แล้วข้อมูลก็จะเป็นภาษาไทยใน database

พอแสดงผล ออกมาเป็น utf-8 มันก็จะแสดงได้ เพราะว่าข้อมูลใน mysql เป็น tis-620

หวังว่าคงช่วยได้นะครับ

เพราะว่าผมก็แก้แล้วใช้ได้ พยายามแก้จนได้ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-04-25 12:31:01 By : nattawa
 


 

No. 28

Guest


หรือกรณี แสดงผล หน้าปกติ (ไม่ได้ออกเป็น pdf)

ตัวหนังสือจะเป็น ???
ให้แก้โดย

@$link = mysql_connect($dbhost, $dbuser, $dbpasswd) or die("<font color=red>Line :".__LINE__."<br>File :".__FILE__."<br>".mysql_error()."<br>".mysql_errno());
mysql_select_db($dbname,$link) or die("<font color=red>Line :".__LINE__."<br>File :".__FILE__."<br>".mysql_error()."<br>".mysql_errno());


// mysql_query("set character set utf8"); // กำหนดค่า character set ที่จะใช้แสดงผล

mysql_query("set character set tis620"); // แสดงค่าจาก utf-8 filed ให้เป็น tis620 ไทย

ก่อนทำการ select ข้อมูลเพื่อแสดงผล file php กรณี file php save เป็น ansi ทั่วไปนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-04-25 14:12:34 By : nattawat suwannatrai
 


 

No. 29

Guest


และในทางกลับกัน ก่อนทำการ insert ข้อมูลเข้า database ซึ่ง field กำหนดเป็น utf-8 ต้องใช้คำสั่ง

mysql_query("SET NAMES tis620");

ก่อนทำการ query insert ข้อมูลนะครับ


สรุปคือ insert ข้อมูล กำหนดเป็น tis620 ใส่ใน field ที่เป็น utf8

และตอนแสดงผลก็กลับออกมาเป็น tis620

mysql_query("set character set tis620"); // แสดงค่าจาก utf-8 filed ให้เป็น tis620 ไทย


ได้แน่นอนครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-04-25 14:17:27 By : nattawat suwannatrai
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยด้วยครับ PHP PDF/FPDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่