001.
<html>
002.
<head>
003.
<title></title>
004.
</head>
005.
<body>
006.
007.
<?php
008.
require
(
'fpdf.php'
);
009.
010.
class
PDF
extends
FPDF
011.
{
012.
013.
function
LoadData(
$file
)
014.
{
015.
016.
$lines
=file(
$file
);
017.
$data
=
array
();
018.
foreach
(
$lines
as
$line
)
019.
$data
[]=
explode
(
';'
,
chop
(
$line
));
020.
return
$data
;
021.
}
022.
023.
024.
function
BasicTable(
$header
,
$data
)
025.
{
026.
027.
$w
=
array
(30,30,55,25,20,20);
028.
029.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
030.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
);
031.
$this
->Ln();
032.
033.
foreach
(
$data
as
$eachResult
)
034.
{
035.
$this
->Cell(30,6,
$eachResult
[
"ID_com"
],1);
036.
$this
->Cell(30,6,
$eachResult
[
"name_com"
],1);
037.
$this
->Cell(55,6,
$eachResult
[
"User"
],1);
038.
$this
->Cell(25,6,
$eachResult
[
"ID_Dep"
],1,0,
'C'
);
039.
$this
->Cell(20,6,
$eachResult
[
"Date"
],1);
040.
$this
->Cell(20,6,
$eachResult
[
"Date"
],1);
041.
$this
->Ln();
042.
}
043.
}
044.
045.
046.
function
ImprovedTable(
$header
,
$data
)
047.
{
048.
049.
$w
=
array
(20,30,55,25,25,25);
050.
051.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
052.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
);
053.
$this
->Ln();
054.
055.
056.
foreach
(
$data
as
$eachResult
)
057.
{
058.
$this
->Cell(20,6,
$eachResult
[
"ID_com"
],1);
059.
$this
->Cell(30,6,
$eachResult
[
"name_com"
],1);
060.
$this
->Cell(55,6,
$eachResult
[
"User"
],1);
061.
$this
->Cell(25,6,
$eachResult
[
"ID_Dep"
],1,0,
'C'
);
062.
$this
->Cell(25,6,number_format(
$eachResult
[
"Date"
],2),1,0,
'R'
);
063.
$this
->Cell(25,6,number_format(
$eachResult
[
"Date"
],2),1,0,
'R'
);
064.
$this
->Ln();
065.
}
066.
067.
068.
069.
070.
071.
072.
$this
->Cell(
array_sum
(
$w
),0,
''
,
'T'
);
073.
}
074.
075.
076.
function
FancyTable(
$header
,
$data
)
077.
{
078.
079.
$this
->SetFillColor(255,0,0);
080.
$this
->SetTextColor(255);
081.
$this
->SetDrawColor(128,0,0);
082.
$this
->SetLineWidth(.3);
083.
$this
->SetFont(
''
,
'B'
);
084.
085.
$w
=
array
(20,30,55,25,25,25);
086.
for
(
$i
=0;
$i
<
count
(
$header
);
$i
++)
087.
$this
->Cell(
$w
[
$i
],7,
$header
[
$i
],1,0,
'C'
,true);
088.
$this
->Ln();
089.
090.
$this
->SetFillColor(224,235,255);
091.
$this
->SetTextColor(0);
092.
$this
->SetFont(
''
);
093.
094.
$fill
=false;
095.
foreach
(
$data
as
$row
)
096.
{
097.
$this
->Cell(
$w
[0],6,
$row
[0],
'LR'
,0,
'L'
,
$fill
);
098.
$this
->Cell(
$w
[1],6,
$row
[1],
'LR'
,0,
'L'
,
$fill
);
099.
$this
->Cell(
$w
[2],6,
$row
[2],
'LR'
,0,
'L'
,
$fill
);
100.
$this
->Cell(
$w
[3],6,
$row
[3],
'LR'
,0,
'C'
,
$fill
);
101.
$this
->Cell(
$w
[4],6,number_format(
$row
[4]),
'LR'
,0,
'R'
,
$fill
);
102.
$this
->Cell(
$w
[5],6,number_format(
$row
[5]),
'LR'
,0,
'R'
,
$fill
);
103.
$this
->Ln();
104.
$fill
=!
$fill
;
105.
}
106.
$this
->Cell(
array_sum
(
$w
),0,
''
,
'T'
);
107.
}
108.
}
109.
110.
$pdf
=
new
PDF();
111.
112.
$header
=
array
(
'ID_com'
,
'name_com'
,
' User'
,
'ID_Dep'
,
'Date'
);
113.
114.
115.
116.
$objConnect
= mysql_connect(
"localhost"
,
"root"
,
"123456"
)
or
die
(
"Error Connect to Database"
);
117.
$objDB
= mysql_select_db(
"datacomputer"
);
118.
$strSQL
=
"SELECT * FROM computer"
;
119.
$objQuery
= mysql_query(
$strSQL
);
120.
$resultData
=
array
();
121.
for
(
$i
=0;
$i
<mysql_num_rows(
$objQuery
);
$i
++) {
122.
$result
= mysql_fetch_array(
$objQuery
);
123.
array_push
(
$resultData
,
$result
);
124.
}
125.
126.
127.
128.
129.
$pdf
->SetFont(
'Arial'
,
''
,10);
130.
131.
132.
$pdf
->AddPage();
133.
$pdf
->Image(
'logo.png'
,80,8,33);
134.
$pdf
->Ln(35);
135.
$pdf
->BasicTable(
$header
,
$resultData
);
136.
137.
138.
$pdf
->AddPage();
139.
$pdf
->Image(
'logo.png'
,80,8,33);
140.
$pdf
->Ln(35);
141.
$pdf
->ImprovedTable(
$header
,
$resultData
);
142.
143.
144.
$pdf
->AddPage();
145.
$pdf
->Image(
'logo.png'
,80,8,33);
146.
$pdf
->Ln(35);
147.
$pdf
->FancyTable(
$header
,
$resultData
);
148.
149.
$pdf
->Output(
"MyPDF/MyPDF.pdf"
,
"F"
);
150.
?>
151.
152.
PDF Created Click <a href=
"../MyPDF/MyPDF.pdf"
>here</a> to Download
153.
</body>
154.
</html>