 |
ช่วยด้วยครับ PHP PDF/FPDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ |
|
 |
|
|
 |
 |
|
ช่วยด้วยครับ PHP PDF/FPDF - MySQL Export to PDF ภาษาไทย มันเป็นภาษาต่างดาวครับ
<?php
require 'fpdf.php';
define('PDF_FONTPATH','font/');
$db= new PDO('mysql:host=localhost;dbname=waterwork','root','bestterry38');
class PDF extends FPDF{
function header(){
$this->Setfont('Arial','B',14);
$this->Cell(276,10,'TEST PaGE Margin',0,0,'C');
$this->Ln();
$this->Setfont('Arial','',12);
$this->Cell(276,10,'sterrt Employee',0,0,'C');
$this->Ln();
}
function footer(){
$this->SetY(-15);
$this->Setfont('Arial','',8);
$this->Cell(0,10,'Page'.$this->PageNo().'/{nb}',0,0,'C');
}
function headertable(){
$this->Cell(40,10,iconv('UTF-8','TIS-620','รหัส'),1,0,'C');
$this->Cell(40,10,iconv('UTF-8','TIS-620','ชื่อ'),1,0,'C');
$this->Cell(40,10,iconv('UTF-8','TIS-620','นามสกุล'),1,0,'C');
$this->Cell(40,10,iconv('UTF-8','TIS-620','บ้านเลขที่'),1,0,'C');
$this->Cell(40,10,iconv('UTF-8','TIS-620','หมู่ที่'),1,0,'C');
$this->Cell(40,10,'UserId',1,0,'C');
$this->Ln();
}
function viewTable($db){
$this->Addfont('angsa','','angsa.php');
$this->SetFont('angsa','','16');
$stmt = $db->query('SELECT * FROM address INNER JOIN datauser ON address.userid=datauser.userid ORDER BY villageno DESC');
mysql_query("SET NAMES 'tis620' ");
while($data = $stmt->fetch(PDO::FETCH_OBJ)){
$this->Cell(40,7,$data->villageid,1,0,'C');
$this->Cell(40,7,$data->name,1,0,'C');
$this->Cell(40,7,$data->lastname,1,0,'L');
$this->Cell(40,7,$data->address,1,0,'L');
$this->Cell(40,7,$data->villageno,1,0,'L');
$this->Cell(40,7,$data->userid,1,0,'L');
$this->Ln();
}
}
}
$pdf = new PDF();
$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','',16);
$pdf->AddPage('L','A4',0);
$pdf->headertable();
$pdf->viewTable($db);
$pdf->Output();
?>
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2017-09-07 23:59:47 |
By :
bestterry |
View :
2080 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
CODE.php
<?php
header('Content-Type: text/html; charset=utf-8');
putenv("NLS_LANG=AMERICAN_AMERICA.TH8TISASCII");
include("include/db_connect.php");
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_unicode_ci'");
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
----------------- Header ------------------
<?php
$filName = "ExportTakeOut.csv"; /// File Name .CSV To Export Excel
fwrite($objWrite, "\xEF\xBB\xBF"); // Write UTF-8 BOM
fwrite($objWrite, "sep=\t" . PHP_EOL); // Hint for MS Excel
$objWrite= "utf8_unicode_ci";
$objWrite = fopen("ExportTakeOut.csv", "w","utf8_unicode_ci");
mb_convert_encoding($Do, 'UTF-16LE', 'UTF-8'); /// Covert $Do to UTF-8
$Do="SELECT bill_out.CodeAuto,
bill_out.BillNo,
bill_out.ProductID,
bill_out.Name,
bill_out.AmountOut
From .....
$Bw=mysql_query($Do) or die("Show Errors $Do ::".mysql_error());
mysql_query("SET NAMES UTF-8");
while($objResult = mysql_fetch_array($Bw))
{
fputs($objWrite, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
++$i;
fwrite($objWrite, ",\"$i\",\"$objResult[BillNo]\",\"$objResult[ProductID]\"n");
fclose($objWrite);
echo "<br>Generate CSV Done.<br><a href=$filName>Download</a>";
?>
Example แบบบ้านๆ PHP 5.3
|
 |
 |
 |
 |
Date :
2017-09-08 09:04:28 |
By :
Bouasavanh HararRock |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|