|
|
PHP PDF สามารถทำแบบในรูปได้รึเปล่าค่ะ มีหลักการยัง เขียนโค้ดเเล้ว ตารางก็ยังไม่ขึ้นมาอยู่ให้เสมอกันอ้ะค้ะ
Code (PHP)
<?php
require('fpdf.php');
define('FPDF_FONTPATH','font/');
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;
}
function Header()
{
$this->Image('image/logo.jpg',5,6,20);
$this->AddFont('cordiab','','cordiab.php');
$this->SetFont('cordiab','',12);
$this->Cell(0,0,iconv( 'UTF-8','TIS-620','หน้าที่... '.$this->PageNo()),0,1,"R");
$this->SetLeftMargin( 30 );
$this->SetLeftMargin( 5 );
$this->Cell(0,5,iconv('UTF-8','TIS-620','บริษัท พะยูนมอเตอร์ จำกัด'), 0 , 1 );
$this->SetLeftMargin( 30 );
$this->Cell(0,5,iconv('UTF-8','TIS-620','เลขที่ 62/49 ถ.วังตอ ต.ทับเที่ยง อ.เมือง จ.ตรัง 92000'), 0 , 1 );
$this->Cell(0,5,iconv('UTF-8','TIS-620','โทรศัพท์ : 081-111-2233'), 0 , 1 );
$this->SetLeftMargin( 5 );
$this->line(5, 28,200,28);
$this->Ln();
//ปัดบรรทัด กำหนดความกว้างของบรรทัด 35 หน่วย
}
function Footer()
{
$this->SetLineWidth(0.1);
include("time.php");
$this->AddFont('cordia','B','cordia.php');
$this->SetFont('cordia','B',12);
//นับจากขอบกระดาษด้านล่างขึ้นมา 15 มม.
$this->SetY(-15);
$this->Cell(0,0,iconv( 'UTF-8','TIS-620',''),1,0,"C");
$this->SetY(-15);
$this->Ln(5);
//พิมพ์วัน-เวลา ตรงมุมขวาล่าง
$this->Cell(0,0,iconv( 'UTF-8','TIS-620','ศูนย์ซ่อมพะยูนมอเตอร์'),0,0,"L");
$this->Cell(0,0,iconv('UTF-8','TIS-620','เวลาพิมพ์ :: '). date('d').'/'. date('m').'/'.( date('Y')+543 ).' '. date('H:i:s') ,0,0,'R');
}
}
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("motor");
$strSQL = "SELECT c.sp_code,c.machine_id,s.chassis_id,s.brand,s.type,c.jing,s.plate,b.brand_name,a.class_name,m.type_name,s.color,s.color1,
e.color_name,f.color_name1,p.province_name,s.province
FROM chk_store c,stock s,brand b,class a,model m,color e,color1 f,province p
WHERE
s.machine_id = c.machine_id AND
s.brand = b.brand_id AND
s.class = a.class_id AND
s.type = m.type_id AND
s.province = p.PROVINCE_ID AND
s.color1 = f.color_id1 AND
s.color = e.color_id AND
c.machine_id = 'LZHR110FF5H009519' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
echo mysql_error();
$brand = $objResult["brand"];
$type = $objResult["type"];
$chassis_id = $objResult["chassis_id"];
$plate = $objResult["plate"];
$color = $objResult["color"];
$color_name1 = $objResult["color_name1"];
$color_name = $objResult["color_name"];
$province_name = $objResult["province_name"];
//end class
$pdf=new PDF('P','mm','A4');
$pdf->AliasNbPages();//จำนวนหน้าทั้งหมด
$pdf->AddPage();
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',17);
$pdf->Cell(0,5,iconv('UTF-8','TIS-620','รายงานรับรถ'), 0 , 1 ,'C' );
$pdf->Ln();
$pdf->SetLeftMargin( 10);
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',14);
$pdf->Cell( 0 , 10 , iconv( 'UTF-8','cp874' , 'หมายเลขเครื่อง :' ) , 0, 1,'L' );
$pdf->Cell( 0 , 10 , iconv( 'UTF-8','cp874' , 'รุ่น :') , 0, 1 );
$pdf->Cell( 0 , 10 , iconv( 'UTF-8','cp874' , 'ป้ายทะเบียน :' ) , 0, 1);
$pdf->SetLeftMargin( 38 );
$pdf->AddFont('cordia','','cordia.php');
$pdf->SetFont('cordia','',14);
$pdf->Cell( 0 , -10, iconv( 'UTF-8','cp874' , $plate.'/'.$province_name) , 0 , 1);
$pdf->Cell( 0 , -10, iconv( 'UTF-8','cp874' , $class_name ) , 0 , 1);
$pdf->Cell( 0 , -10, iconv( 'UTF-8','cp874' , $_GET["mID"] ) , 0 , 1);
$pdf->SetLeftMargin( 80 );
$pdf->Ln(30);
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',14);
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , '' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , 'แบบ :' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , 'หมายเลขตัวถัง :') , 0 , 1);
$pdf->SetLeftMargin( 108 );
$pdf->Ln(30);
$pdf->AddFont('cordia','','cordia.php');
$pdf->SetFont('cordia','',14);
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , '' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , $type_name ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , $chassis_id ) , 0 , 1 );
$pdf->SetLeftMargin( 145 );
$pdf->Ln(30);
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',14);
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , '' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , 'สี :' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , 'ยี่ห้อ :' ) , 0 , 1 );
$pdf->SetLeftMargin( 170 );
$pdf->Ln(30);
$pdf->AddFont('cordia','','cordia.php');
$pdf->SetFont('cordia','',14);
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , '' ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , $color_name.'/'.$color_name1 ) , 0 , 1 );
$pdf->Cell( 0 , -10 , iconv( 'UTF-8','cp874' , $brand_name ) , 0 , 1 );
$pdf->SetLeftMargin( 5 );
$pdf->Ln(30);
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',12);
$pdf->SetFillColor(224,235,255);
$pdf->Cell(5,7,iconv('UTF-8','TIS-620','#'),1,0,'C',true);
$pdf->Cell(40,7,iconv('UTF-8','TIS-620','รายการ'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','มี'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ไม่มี'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ชำรุด'),1,0,'C',true);
$pdf->Cell(15,7,iconv('UTF-8','TIS-620','ใช้งานไม่ได้'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ใช้ได้'),1,0,'C',true);
$pdf->Ln();
$pdf->SetLeftMargin( 5 );
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("motor");
$strSQL = "SELECT * FROM chk_store c WHERE c.machine_id = 'LZHR110FF5H009519' ORDER BY c.chk_id ";
$objQuery = mysql_query($strSQL);
$rows = mysql_num_rows($objQuery);
$num=1; //ลำดับที่ 123
$i=0;
$rows=25;
while($objResult = mysql_fetch_array($objQuery))
{
$i++;
$sp_code = $objResult["sp_code"];
$sp_name = $objResult["sp_name"];
$jing = $objResult["jing"];
$sapab = $objResult["sapab"];
$pdf->AddFont('cordia','','cordia.php');
$pdf->SetFont('cordia','',12);
$pdf->cell(5,8,$num.'.',1,0,'C');
$pdf->cell(40,8,iconv('UTF-8','TIS-620',$sp_name),1,0);
if($jing =='1')
{
$mee1 = 'image/ok1.jpg';
}else if($jing =='2')
{
$mee1 = 'image/wh.jpg';
}
if($jing =='2')
{
$mee = 'image/ok1.jpg';
}else if($jing =='1')
{
$mee = 'image/wh.jpg';
}
//end mee
//ขำรุด
if($sapab =='1')
{
$sapab1 = 'image/ok1.jpg';
}else
{
$sapab1 = 'image/wh.jpg';
}
if($sapab =='2')
{
$sapab2 = 'image/ok1.jpg';
}else
{
$sapab2 = 'image/wh.jpg';
}
if($sapab =='3')
{
$sapab3 = 'image/ok1.jpg';
}else
{
$sapab3 = 'image/wh.jpg';
}
//ใช้ได้
$pdf->Image('./image/ok1.jpg',18,5,-150);
$pdf->cell(10,8,$pdf->Image($mee1,$pdf->GetX(),$pdf->GetY(),6,6,'',$mee1),1,0);
$pdf->cell(10,8,$pdf->Image($mee,$pdf->GetX(),$pdf->GetY(),6,6,'',$mee),1,0);
$pdf->cell(10,8,$pdf->Image($sapab1,$pdf->GetX(),$pdf->GetY(),6,6,'',$sapab1),1,0);
$pdf->cell(15,8,$pdf->Image($sapab2,$pdf->GetX(),$pdf->GetY(),6,6,'',$sapab2),1,0);
$pdf->cell(10,8,$pdf->Image($sapab3,$pdf->GetX(),$pdf->GetY(),6,6,'',$sapab3),1,0);
$pdf->Ln();
if ($i%$rows==0)
{
$pdf->SetLeftMargin( 107 );
$pdf->AddFont('cordiab','','cordiab.php');
$pdf->SetFont('cordiab','',12);
$pdf->SetFillColor(224,235,255);
$pdf->Cell(5,7,iconv('UTF-8','TIS-620','#'),1,0,'C',true);
$pdf->Cell(40,7,iconv('UTF-8','TIS-620','รายการ'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','มี'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ไม่มี'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ชำรุด'),1,0,'C',true);
$pdf->Cell(15,7,iconv('UTF-8','TIS-620','ใช้งานไม่ได้'),1,0,'C',true);
$pdf->Cell(10,7,iconv('UTF-8','TIS-620','ใช้ได้'),1,0,'C',true);
$pdf->Ln();
$pdf->SetLeftMargin( 107 );
for($i=0;$i<count($header);$i++)
$pdf->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]));
$i=0;
$rows=25;
}
$num++;
}
$pdf->Ln();
$pdf->SetLeftMargin( 107 );
$pdf->SetLineWidth(0.1);
$pdf->Cell(0,9,iconv('UTF-8','TIS-620','ลงชื่อ_________________________________________ผู้ตรวจสภาพ'),0,1,'R');
$pdf->Cell(0,9,iconv('UTF-8','TIS-620',$userid.$fname),0,1,'R');
$pdf->Cell(0,9,iconv('UTF-8','TIS-620','วันที่_____________/_____________/_____________'),0,1,'R');
$pdf->Cell(0,9,iconv('UTF-8','TIS-620','ลงชื่อ______________________________________ผู้จัดการสาขา'),0,1,'R');
$pdf->Cell(0,9,iconv('UTF-8','TIS-620','วันที่_____________/_____________/_____________'),0,1,'R');
$pdf->Output("report_error.pdf","F");
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2013-06-28 10:27:25 |
By :
PALM26 |
View :
1034 |
Reply :
1 |
|
|
|
|
|
|
|
|
|