001.
<?php
002.
require
(
'fpdf.php'
);
003.
define(
'FPDF_FONTPATH'
,
'font/'
);
004.
005.
class
PDF
extends
FPDF
006.
{
007.
008.
function
LoadData(
$file
)
009.
{
010.
011.
$lines
=file(
$file
);
012.
$data
=
array
();
013.
foreach
(
$lines
as
$line
)
014.
$data
[]=
explode
(
';'
,
chop
(
$line
));
015.
return
$data
;
016.
}
017.
018.
019.
function
BasicTable(
$header
,
$data
)
020.
{
021.
022.
$w
=
array
(15,20,25,30,35,25,25);
023.
024.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
025.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
);
026.
$this
->Ln();
027.
028.
foreach
(
$data
as
$eachResult
)
029.
{
030.
$this
->Cell(15,6,
$eachResult
[
"expose_id"
],1,0,
'C'
);
031.
$this
->Cell(20,6,
$eachResult
[
"expose_product"
],1,0,
'C'
);
032.
$this
->Cell(25,6,
$eachResult
[
"expose_number"
],1,0,
'C'
);
033.
$this
->Cell(30,6 ,
$eachResult
[
"expose_name"
],1,0,
'C'
);
034.
$this
->Cell(35,6,
$eachResult
[
"expose_lastname"
],1,0,
'C'
);
035.
$this
->Cell(25,6,
$eachResult
[
"product_code"
],1,0,
'C'
);
036.
$this
->Cell(25,6,
$eachResult
[
"day"
],1,0,
'C'
);
037.
$this
->Ln();
038.
}
039.
}
040.
041.
042.
function
ImprovedTable(
$header
,
$data
)
043.
{
044.
045.
$w
=
array
(15,20,25,30,35,25,25);
046.
047.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
048.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
);
049.
$this
->Ln();
050.
051.
052.
foreach
(
$data
as
$eachResult
)
053.
{
054.
$this
->Cell(15,6,
$eachResult
[
"expose_id"
],1,0,
'C'
);
055.
$this
->Cell(20,6,
$eachResult
[
"expose_product"
],1,0,
'C'
);
056.
$this
->Cell(25,6,
$eachResult
[
"expose_number"
],1,0,
'C'
);
057.
$this
->Cell(30,6 ,
$eachResult
[
"expose_name"
],1,0,
'C'
);
058.
$this
->Cell(35,6,
$eachResult
[
"expose_lastname"
],1,0,
'C'
);
059.
$this
->Cell(25,6,
$eachResult
[
"product_code"
],1,0,
'C'
);
060.
$this
->Cell(25,6,number_format(
$eachResult
[
"day"
],2),1,0,
'C'
);
061.
$this
->Ln();
062.
}
063.
064.
065.
066.
067.
068.
069.
070.
$this
->Cell(
array_sum
(
$w
),0,
''
,
'T'
);
071.
}
072.
073.
074.
function
FancyTable(
$header
,
$data
)
075.
{
076.
077.
$this
->SetFillColor(255,0,0);
078.
$this
->SetTextColor(255);
079.
$this
->SetDrawColor(128,0,0);
080.
$this
->SetLineWidth(.3);
081.
$this
->SetFont(
''
,
'B'
);
082.
083.
$w
=
array
(15,20,25,30,35,25,25);
084.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
085.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
,true);
086.
$this
->Ln();
087.
088.
$this
->SetFillColor(224,235,255);
089.
$this
->SetTextColor(0);
090.
$this
->SetFont(
''
);
091.
092.
$fill
=false;
093.
foreach
(
$data
as
$row
)
094.
{
095.
$this
->Cell(
$w
[0],6,
$row
[0],
'LR'
,0,
'L'
,
$fill
);
096.
$this
->Cell(
$w
[1],6,
$row
[1],
'LR'
,0,
'L'
,
$fill
);
097.
$this
->Cell(
$w
[2],6,
$row
[2],
'LR'
,0,
'L'
,
$fill
);
098.
$this
->Cell(
$w
[3],6,
$row
[3],
'LR'
,0,
'C'
,
$fill
);
099.
$this
->Cell(
$w
[4],6,number_format(
$row
[4]),
'LR'
,0,
'R'
,
$fill
);
100.
$this
->Cell(
$w
[5],6,number_format(
$row
[5]),
'LR'
,0,
'R'
,
$fill
);
101.
$this
->Ln();
102.
$fill
=!
$fill
;
103.
}
104.
$this
->Cell(
array_sum
(
$w
),0,
''
,
'T'
);
105.
}
106.
}
107.
108.
$pdf
=
new
PDF();
109.
110.
$header
=
array
(
'รหัส'
,
'สินค้า'
,
'จำนวนเบิก'
,
'ชื่อ'
,
'นามสกุล'
,
'รหัสสินค้า'
,
'วันที่เบิก'
);
111.
112.
113.
114.
$objConnect
= mysql_connect(
"localhost"
,
"344057"
,
"12345678"
)
or
die
(
"Error Connect to Database"
);
115.
$objDB
= mysql_select_db(
"344057"
);
116.
mysql_query(
"set NAMES'UTF8'"
);
117.
$strSQL
=
"SELECT * FROM expose "
;
118.
$objQuery
= mysql_query(
$strSQL
);
119.
$resultData
=
array
();
120.
for
(
$i
=0;
$i
<mysql_num_rows(
$objQuery
);
$i
++) {
121.
$result
= mysql_fetch_array(
$objQuery
);
122.
array_push
(
$resultData
,
$result
);
123.
}
124.
125.
126.
$pdf
->AddFont(
'angsana'
,
''
,
'angsa.php'
);
127.
128.
129.
$pdf
->AddFont(
'angsana'
,
'B'
,
'angsab.php'
);
130.
131.
132.
$pdf
->AddFont(
'angsana'
,
'I'
,
'angsai.php'
);
133.
134.
135.
$pdf
->AddFont(
'angsana'
,
'BI'
,
'angsaz.php'
);
136.
137.
138.
$pdf
->SetFont(
'angsana'
,
''
,12);
139.
140.
141.
$pdf
->AddPage();
142.
$pdf
->Image(
'logo.png'
,80,8,33);
143.
$pdf
->Ln(35);
144.
$pdf
->BasicTable(
$header
,
$resultData
);
145.
146.
147.
$pdf
->AddPage();
148.
$pdf
->Image(
'logo.png'
,80,8,33);
149.
$pdf
->Ln(35);
150.
$pdf
->ImprovedTable(
$header
,
$resultData
);
151.
152.
153.
$pdf
->AddPage();
154.
$pdf
->Image(
'logo.png'
,80,8,33);
155.
$pdf
->Ln(35);
156.
$pdf
->FancyTable(
$header
,
$resultData
);
157.
158.
$pdf
->Output(
"MyPDF/MyPDF.pdf"
,
"F"
);
159.
?>
160.
161.
PDF Created Click <a href=
"MyPDF/MyPDF.pdf"
>here</a> to Download
162.
</body>
163.
</html>