001.
<?php
002.
003.
004.
005.
$path
=
"C:\\user\\web\\tcpdf_5_5_001"
;
006.
set_include_path(get_include_path() . PATH_SEPARATOR .
$path
);
007.
008.
009.
010.
011.
require_once
(
'tcpdf/config/lang/eng.php'
);
012.
require_once
(
'tcpdf/tcpdf.php'
);
013.
014.
015.
016.
017.
if
(
substr
(PHP_OS,0,3) ==
'WIN'
) {
018.
if
( !
extension_loaded
(
"mysql"
) ) {
019.
dl(
"php_mysql.dll"
);
020.
}
021.
}
022.
023.
024.
025.
026.
$Server
=
'localhost'
;
027.
$DbName
=
'lightbox'
;
028.
$User
=
'root'
;
029.
$Password
=
'password'
;
030.
031.
032.
033.
034.
$Connect
= @mysql_connect(
$Server
,
$User
,
$Password
);
035.
if
( !
$Connect
) {
036.
header(
"Content-Type: text/html; Charset=euc-jp"
);
037.
038.
mb_language(
"ja"
);
039.
mb_internal_encoding(
"UTF-8"
);
040.
$str
= mb_convert_encoding(
"接続エラーです"
,
"euc-jp"
,
"utf-8"
);
041.
print
$str
;
042.
043.
exit
();
044.
}
045.
046.
047.
048.
049.
050.
051.
052.
053.
054.
055.
056.
057.
058.
059.
060.
mysql_select_db(
$DbName
,
$Connect
);
061.
062.
063.
064.
065.
$query
=
"select 社員マスタ.*,DATE_FORMAT(生年月日,'%Y-%m-%d') as 誕生日"
;
066.
$query
.=
" from 社員マスタ"
;
067.
$result
= mysql_query(
$query
,
$Connect
);
068.
069.
070.
071.
072.
073.
074.
075.
076.
077.
078.
079.
080.
081.
082.
083.
084.
085.
086.
087.
088.
089.
090.
091.
092.
093.
$pdf
=
new
TCPDF(
094.
PDF_PAGE_ORIENTATION,
095.
PDF_UNIT,
096.
PDF_PAGE_FORMAT,
097.
true,
098.
"UTF-8"
,
099.
false
100.
);
101.
102.
103.
104.
$pdf
->setPrintHeader(false);
105.
$pdf
->setPrintFooter(false);
106.
107.
108.
109.
110.
111.
112.
113.
$line_no
= 0;
114.
$line_max
= 10;
115.
$data_top
= 25;
116.
$data_left
= 10;
117.
118.
119.
120.
121.
$pdf
->AddPage();
122.
123.
124.
125.
126.
127.
$pdf
->SetFont(
'arialunicid0'
,
''
, 8);
128.
129.
130.
131.
132.
while
(
$row
= mysql_fetch_array(
$result
, MYSQL_BOTH)) {
133.
134.
135.
136.
if
(
$line_no
== 0 ||
$line_no
>
$line_max
) {
137.
user_titie(
$pdf
);
138.
}
139.
140.
141.
142.
143.
144.
$row_position
=
$data_top
+ 5 +(
$line_no
-3) * 5;
145.
text(
$pdf
,
$data_left
+ 0,
$row_position
,
$row
[
'社員コード'
] );
146.
text(
$pdf
,
$data_left
+ 15,
$row_position
,
$row
[
'氏名'
] );
147.
148.
textR(
$pdf
,
$data_left
+ 35,
$row_position
, user_number_format(
$row
[
'給与'
]), 20 );
149.
150.
151.
$line_no
++;
152.
153.
}
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
$pdf
->Output(
"sample.pdf"
,
"I"
);
166.
167.
168.
169.
170.
mysql_close(
$Connect
);
171.
172.
173.
174.
175.
176.
function
user_titie(
$pdf
) {
177.
178.
global
$line_no
;
179.
global
$data_top
,
$data_left
;
180.
181.
182.
if
(
$line_no
!= 0 ) {
183.
$pdf
->AddPage();
184.
}
185.
186.
187.
188.
$pdf
->Image(
189.
'./winofsql.png'
,
190.
10,
191.
3,
192.
0,
193.
0,
194.
'PNG'
,
195.
'http://winofsql.jp/'
,
196.
''
,
197.
false,
198.
300,
199.
''
,
200.
false,
201.
false,
202.
0,
203.
false,
204.
false,
205.
false
206.
);
207.
208.
209.
$pdf
->SetFont(
'arialunicid0'
,
''
, 40);
210.
text(
$pdf
, 40, 0,
"社員一覧表"
);
211.
212.
$pdf
->SetFont(
'arialunicid0'
,
''
, 8);
213.
text(
$pdf
,
$data_left
+ 0,
$data_top
+ 0,
"社員CD"
);
214.
text(
$pdf
,
$data_left
+ 15,
$data_top
+ 0,
"氏名"
);
215.
textR(
$pdf
,
$data_left
+ 35,
$data_top
+ 0,
"給与"
, 20 );
216.
217.
$line_no
= 3;
218.
219.
}
220.
221.
222.
223.
224.
function
user_number_format(
$param
) {
225.
226.
if
( trim(
$param
) ==
''
) {
227.
$param
=
"0"
;
228.
}
229.
230.
return
number_format(
$param
);
231.
232.
}
233.
234.
235.
236.
237.
function
text(
$pdf
,
$x
=0,
$y
=0,
$txt
=
''
,
$w
=1,
$h
=0 ) {
238.
239.
$a
=
$pdf
->GetX();
240.
$b
=
$pdf
->GetY();
241.
242.
$pdf
->SetXY(
$x
,
$y
);
243.
$pdf
->Cell(
$w
,
$h
,
$txt
, 0, 0,
'L'
);
244.
245.
$pdf
->SetXY(
$a
,
$b
);
246.
247.
}
248.
249.
250.
251.
252.
function
textR(
$pdf
,
$x
=0,
$y
=0,
$txt
=
''
,
$w
=1,
$h
=0 ) {
253.
254.
$a
=
$pdf
->GetX();
255.
$b
=
$pdf
->GetY();
256.
257.
$pdf
->SetXY(
$x
,
$y
);
258.
$pdf
->Cell(
$w
,
$h
,
$txt
, 0, 0,
'R'
);
259.
260.
$pdf
->SetXY(
$a
,
$b
);
261.
262.
}
263.
264.
?>