|
|
|
fpdf ไม่เป็นไทยครับช่วยหน่อย...FPDF error: Undefined font: angsana . |
|
|
|
|
|
|
|
Code (PHP)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="imagesnew/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="imagesnew/favicon.ico" type="image/x-icon" />
<title>SERVICE ACKNOWLEDGEMENT REPORT (SAR)</title>
<?php
require('fpdf.php');
include ('adodb/adodb.inc.php');
define('FPDF_FONTPATH','fpdf/font/');
require ('fpdf/jpdf.inc.php');
$pdf=new JPDF();
$pdf->AddFont('angsana','B','angsanab.php');
$pdf->AddFont('angsana','','angsana.php');
$pdf->Open();
$pdf->AliasNbPages();
$pdf->AddPage();
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(25,20,20,30,70,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(25,6,$eachResult["DATE"],1);
$this->Cell(20,6,$eachResult["TIMEIN"],1);
$this->Cell(20,6,$eachResult["TIMEOUT"],1,0,'C');
$this->Cell(30,6,$eachResult["CUSTOMERS"],1);
$this->Cell(70,6,$eachResult["TASK"],1);
$this->Cell(20,6,$eachResult["REMARKS"],1);
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(10,20,20,30,70,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(10,6,$eachResult["id"],1);
$this->Cell(20,6,$eachResult["TIMEIN"],1);
$this->Cell(20,6,$eachResult["TIMEOUT"],1);
$this->Cell(30,6,$eachResult["CUSTOMERS"],1);
$this->Cell(70,6,$eachResult["TASK"],1);
$this->Cell(20,6,$eachResult["REMARKS"],1);
$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(10,20,20,30,70,20);
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->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('DATE','TIMEIN','TIMEOUT','CUSTOMER','TASK','REMARKS');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("sarnewtest");
$test=$_POST["MONTH"];
$test2=$_POST["YEAR"];
$strSQL = "select * from sar where MONTH='$test' AND YEAR='$test2'";
$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->cell(0,7,'SERVICE ACKNOWLEDGEMENT REPORT (SAR)กกกก',0,0,'C');
$pdf->Ln(15);
$pdf->cell(0,7,'NAME: '.$result["NAME"].' Signature : . . . . . . . . . . . . . . . . . . . . . .'.' MONTH: '.$result["MONTH"].' '.$result["YEAR"],0,0,'L');
$pdf->Ln(10);
$pdf->BasicTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2011-02-10 21:00:01 |
By :
satonpanit |
View :
9683 |
Reply :
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FPDF error: Undefined font: angsana
มันบอกว่าไม่เจอทั้งๆๆที่มันมทำอย่างงัยครับ
|
|
|
|
|
Date :
2011-02-11 08:19:33 |
By :
satonpanit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดาวโหลดฟ้อนท์ไทยมายัง
|
|
|
|
|
Date :
2011-02-11 08:44:44 |
By :
avsqlz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มีแล้วครับพอใส่ ฟังก์ชันี้ไปก็บอกหา font ไม่เจออะCode (PHP)
class PDF extends FPDF
{
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(25,20,20,30,70,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(25,6,$eachResult["DATE"],1);
$this->Cell(20,6,$eachResult["TIMEIN"],1);
$this->Cell(20,6,$eachResult["TIMEOUT"],1,0,'C');
$this->Cell(30,6,$eachResult["CUSTOMERS"],1);
$this->Cell(70,6,$eachResult["TASK"],1);
$this->Cell(20,6,$eachResult["REMARKS"],1);
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(10,20,20,30,70,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(10,6,$eachResult["id"],1);
$this->Cell(20,6,$eachResult["TIMEIN"],1);
$this->Cell(20,6,$eachResult["TIMEOUT"],1);
$this->Cell(30,6,$eachResult["CUSTOMERS"],1);
$this->Cell(70,6,$eachResult["TASK"],1);
$this->Cell(20,6,$eachResult["REMARKS"],1);
$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(10,20,20,30,70,20);
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->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('DATE','TIMEIN','TIMEOUT','CUSTOMER','TASK','REMARKS');
//Data loading
//*** Load MySQL Data ***//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("sarnewtest");
$test=$_POST["MONTH"];
$test2=$_POST["YEAR"];
$strSQL = "select * from sar where MONTH='$test' AND YEAR='$test2'";
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
|
|
|
|
|
Date :
2011-02-11 09:00:45 |
By :
satonpanit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้วครับขอบคุณทุกๆๆคนนะ
|
|
|
|
|
Date :
2011-02-11 09:21:29 |
By :
satonpanit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณ satonpanit ครับ รบกวนบอกหน่อยสิครับ ทำอย่างไงถึงอ่านภาษาไทยได้ครับ
ผมกำลังติดปัญหานี้อยู่เลยครับ พยายามแก้มาหลายวันแล้ว แต่ก็ทำไมไ่ด้สักทีครับ
รบกวนหน่อยครับ
|
|
|
|
|
Date :
2011-10-13 11:47:53 |
By :
eak |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมเคยแก้แต่ RedMine ซึ่งมันเขียนโดย RoR โดยมันใช้ตัวแปลงเป็น pdf คือ rfpdf จึงจริงๆ มันคือ port ของ fpdf ไปลง RoR
น่าจะเทียบเคียงกันได้หรือเปล่า ใช้ redmine/vendor/plugins/rfpdf/lib/fonts/ttf2ufm แปลงให้ได้ *.rb *.ctg.z *.z ( มันมี readme อ่านดูครับ ) จากนั้นก็วางลง redmine/vendor/plugins/rfpdf/lib/fonts
ถ้าจำไม่ผิด font ผมหาจาก GNU FreeFont
|
|
|
|
|
Date :
2011-10-13 23:58:01 |
By :
ohmohm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้ยังไงอ่ะคะ ช่วยชี้แจงนิดนึงอ่ะค่ะ อยากรู้ >< เพราะทไไม่ได้ แหะๆ
|
|
|
|
|
Date :
2012-08-16 10:30:54 |
By :
ีืun |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?php
define('FPDF_FONTPATH','font/');
require('fpdf.php');
$objConnect = mysql_connect("localhost","root","5471") or die("Error Connect to Database");
$objDB = mysql_select_db("bansuk_moo7");
mysql_query("SET NAMES 'tis620' ");
$strSQL = "SELECT * FROM member_user";
$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(20,60,20,55,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', 'TIS-620', $header[$i]),1,0,'C');
$this->Ln();
//Data
foreach ($data as $eachResult)
{
$this->Cell(30,6,$eachResult["id_user"],1);
//$this->Cell(30,6,$eachResult["Name"],1);
$this->Cell(30,6,iconv('UTF-8', 'TIS-620',$eachResult["name"]),1);
$this->Cell(55,6,$eachResult["address"],1);
$this->Cell(25,6,$eachResult["id_peole"],1,0,'C');
$this->Cell(20,6,$eachResult["birday"],1);
$this->Ln();
}
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(20,60,20,55,20);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $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["id_user"],1 );
$this->Cell(30,6,$eachResult["name"],1);
$this->Cell(55,6,$eachResult["address"],1);
$this->Cell(25,6,$eachResult["id_peole"],1,0,'C');
$this->Cell(25,6,$eachResult["birday"],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,60,20,55,20);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $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,$row[4],'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');
//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 3 ***//
$pdf->AddPage();
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output();
?>
นี้ครับ.....จัดเต็มเลยไปแก้ไขตรงฐานข้อมูลเอานะครับ
|
|
|
|
|
Date :
2013-03-15 17:50:22 |
By :
007 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|