296 |
aurelien |
1 |
<?php
|
|
|
2 |
//============================================================+
|
|
|
3 |
// File name : example_048.php
|
|
|
4 |
// Begin : 2009-03-20
|
|
|
5 |
// Last Update : 2010-08-08
|
|
|
6 |
//
|
|
|
7 |
// Description : Example 048 for TCPDF class
|
|
|
8 |
// HTML tables and table headers
|
|
|
9 |
//
|
|
|
10 |
// Author: Nicola Asuni
|
|
|
11 |
//
|
|
|
12 |
// (c) Copyright:
|
|
|
13 |
// Nicola Asuni
|
|
|
14 |
// Tecnick.com s.r.l.
|
|
|
15 |
// Via Della Pace, 11
|
|
|
16 |
// 09044 Quartucciu (CA)
|
|
|
17 |
// ITALY
|
|
|
18 |
// www.tecnick.com
|
|
|
19 |
// info@tecnick.com
|
|
|
20 |
//============================================================+
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Creates an example PDF TEST document using TCPDF
|
|
|
24 |
* @package com.tecnick.tcpdf
|
|
|
25 |
* @abstract TCPDF - Example: HTML tables and table headers
|
|
|
26 |
* @author Nicola Asuni
|
|
|
27 |
* @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
|
|
|
28 |
* @link http://tcpdf.org
|
|
|
29 |
* @license http://www.gnu.org/copyleft/lesser.html LGPL
|
|
|
30 |
* @since 2009-03-20
|
|
|
31 |
*/
|
|
|
32 |
|
|
|
33 |
require_once('../config/lang/eng.php');
|
|
|
34 |
require_once('../tcpdf.php');
|
|
|
35 |
|
|
|
36 |
// create new PDF document
|
|
|
37 |
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
|
|
|
38 |
|
|
|
39 |
// set document information
|
|
|
40 |
$pdf->SetCreator(PDF_CREATOR);
|
|
|
41 |
$pdf->SetAuthor('Nicola Asuni');
|
|
|
42 |
$pdf->SetTitle('TCPDF Example 048');
|
|
|
43 |
$pdf->SetSubject('TCPDF Tutorial');
|
|
|
44 |
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
|
|
|
45 |
|
|
|
46 |
// set default header data
|
|
|
47 |
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);
|
|
|
48 |
|
|
|
49 |
// set header and footer fonts
|
|
|
50 |
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
|
|
|
51 |
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
|
|
|
52 |
|
|
|
53 |
// set default monospaced font
|
|
|
54 |
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
55 |
|
|
|
56 |
//set margins
|
|
|
57 |
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
58 |
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
|
|
|
59 |
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
|
|
|
60 |
|
|
|
61 |
//set auto page breaks
|
|
|
62 |
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
63 |
|
|
|
64 |
//set image scale factor
|
|
|
65 |
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
66 |
|
|
|
67 |
//set some language-dependent strings
|
|
|
68 |
$pdf->setLanguageArray($l);
|
|
|
69 |
|
|
|
70 |
// ---------------------------------------------------------
|
|
|
71 |
|
|
|
72 |
// set font
|
|
|
73 |
$pdf->SetFont('helvetica', 'B', 20);
|
|
|
74 |
|
|
|
75 |
// add a page
|
|
|
76 |
$pdf->AddPage();
|
|
|
77 |
|
|
|
78 |
$pdf->Write(0, 'Example of HTML tables', '', 0, 'L', true, 0, false, false, 0);
|
|
|
79 |
|
|
|
80 |
$pdf->SetFont('helvetica', '', 8);
|
|
|
81 |
|
|
|
82 |
// -----------------------------------------------------------------------------
|
|
|
83 |
|
|
|
84 |
$tbl = <<<EOD
|
|
|
85 |
<table cellspacing="0" cellpadding="1" border="1">
|
|
|
86 |
<tr>
|
|
|
87 |
<td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3</td>
|
|
|
88 |
<td>COL 2 - ROW 1</td>
|
|
|
89 |
<td>COL 3 - ROW 1</td>
|
|
|
90 |
</tr>
|
|
|
91 |
<tr>
|
|
|
92 |
<td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
|
|
|
93 |
<td>COL 3 - ROW 2</td>
|
|
|
94 |
</tr>
|
|
|
95 |
<tr>
|
|
|
96 |
<td>COL 3 - ROW 3</td>
|
|
|
97 |
</tr>
|
|
|
98 |
|
|
|
99 |
</table>
|
|
|
100 |
EOD;
|
|
|
101 |
|
|
|
102 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
103 |
|
|
|
104 |
// -----------------------------------------------------------------------------
|
|
|
105 |
|
|
|
106 |
$tbl = <<<EOD
|
|
|
107 |
<table cellspacing="0" cellpadding="1" border="1">
|
|
|
108 |
<tr>
|
|
|
109 |
<td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3<br />text line<br />text line<br />text line<br />text line<br />text line<br />text line</td>
|
|
|
110 |
<td>COL 2 - ROW 1</td>
|
|
|
111 |
<td>COL 3 - ROW 1</td>
|
|
|
112 |
</tr>
|
|
|
113 |
<tr>
|
|
|
114 |
<td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
|
|
|
115 |
<td>COL 3 - ROW 2</td>
|
|
|
116 |
</tr>
|
|
|
117 |
<tr>
|
|
|
118 |
<td>COL 3 - ROW 3</td>
|
|
|
119 |
</tr>
|
|
|
120 |
|
|
|
121 |
</table>
|
|
|
122 |
EOD;
|
|
|
123 |
|
|
|
124 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
125 |
|
|
|
126 |
// -----------------------------------------------------------------------------
|
|
|
127 |
|
|
|
128 |
$tbl = <<<EOD
|
|
|
129 |
<table cellspacing="0" cellpadding="1" border="1">
|
|
|
130 |
<tr>
|
|
|
131 |
<td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3<br />text line<br />text line<br />text line<br />text line<br />text line<br />text line</td>
|
|
|
132 |
<td>COL 2 - ROW 1</td>
|
|
|
133 |
<td>COL 3 - ROW 1</td>
|
|
|
134 |
</tr>
|
|
|
135 |
<tr>
|
|
|
136 |
<td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
|
|
|
137 |
<td>COL 3 - ROW 2<br />text line<br />text line</td>
|
|
|
138 |
</tr>
|
|
|
139 |
<tr>
|
|
|
140 |
<td>COL 3 - ROW 3</td>
|
|
|
141 |
</tr>
|
|
|
142 |
|
|
|
143 |
</table>
|
|
|
144 |
EOD;
|
|
|
145 |
|
|
|
146 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
147 |
|
|
|
148 |
// -----------------------------------------------------------------------------
|
|
|
149 |
|
|
|
150 |
$tbl = <<<EOD
|
|
|
151 |
<table border="1">
|
|
|
152 |
<tr>
|
|
|
153 |
<th rowspan="3">Left column</th>
|
|
|
154 |
<th colspan="5">Heading Column Span 5</th>
|
|
|
155 |
<th colspan="9">Heading Column Span 9</th>
|
|
|
156 |
</tr>
|
|
|
157 |
<tr>
|
|
|
158 |
<th rowspan="2">Rowspan 2<br />This is some text that fills the table cell.</th>
|
|
|
159 |
<th colspan="2">span 2</th>
|
|
|
160 |
<th colspan="2">span 2</th>
|
|
|
161 |
<th rowspan="2">2 rows</th>
|
|
|
162 |
<th colspan="8">Colspan 8</th>
|
|
|
163 |
</tr>
|
|
|
164 |
<tr>
|
|
|
165 |
<th>1a</th>
|
|
|
166 |
<th>2a</th>
|
|
|
167 |
<th>1b</th>
|
|
|
168 |
<th>2b</th>
|
|
|
169 |
<th>1</th>
|
|
|
170 |
<th>2</th>
|
|
|
171 |
<th>3</th>
|
|
|
172 |
<th>4</th>
|
|
|
173 |
<th>5</th>
|
|
|
174 |
<th>6</th>
|
|
|
175 |
<th>7</th>
|
|
|
176 |
<th>8</th>
|
|
|
177 |
</tr>
|
|
|
178 |
</table>
|
|
|
179 |
EOD;
|
|
|
180 |
|
|
|
181 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
182 |
|
|
|
183 |
// -----------------------------------------------------------------------------
|
|
|
184 |
|
|
|
185 |
// Table with rowspans and THEAD
|
|
|
186 |
$tbl = <<<EOD
|
|
|
187 |
<table border="1" cellpadding="2" cellspacing="2">
|
|
|
188 |
<thead>
|
|
|
189 |
<tr style="background-color:#FFFF00;color:#0000FF;">
|
|
|
190 |
<td width="30" align="center"><b>A</b></td>
|
|
|
191 |
<td width="140" align="center"><b>XXXX</b></td>
|
|
|
192 |
<td width="140" align="center"><b>XXXX</b></td>
|
|
|
193 |
<td width="80" align="center"> <b>XXXX</b></td>
|
|
|
194 |
<td width="80" align="center"><b>XXXX</b></td>
|
|
|
195 |
<td width="45" align="center"><b>XXXX</b></td>
|
|
|
196 |
</tr>
|
|
|
197 |
<tr style="background-color:#FF0000;color:#FFFF00;">
|
|
|
198 |
<td width="30" align="center"><b>B</b></td>
|
|
|
199 |
<td width="140" align="center"><b>XXXX</b></td>
|
|
|
200 |
<td width="140" align="center"><b>XXXX</b></td>
|
|
|
201 |
<td width="80" align="center"> <b>XXXX</b></td>
|
|
|
202 |
<td width="80" align="center"><b>XXXX</b></td>
|
|
|
203 |
<td width="45" align="center"><b>XXXX</b></td>
|
|
|
204 |
</tr>
|
|
|
205 |
</thead>
|
|
|
206 |
<tr>
|
|
|
207 |
<td width="30" align="center">1.</td>
|
|
|
208 |
<td width="140" rowspan="6">XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
|
|
|
209 |
<td width="140">XXXX<br />XXXX</td>
|
|
|
210 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
211 |
<td width="80">XXXX</td>
|
|
|
212 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
213 |
</tr>
|
|
|
214 |
<tr>
|
|
|
215 |
<td width="30" align="center" rowspan="3">2.</td>
|
|
|
216 |
<td width="140" rowspan="3">XXXX<br />XXXX</td>
|
|
|
217 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
218 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
219 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
220 |
</tr>
|
|
|
221 |
<tr>
|
|
|
222 |
<td width="80">XXXX<br />XXXX<br />XXXX<br />XXXX</td>
|
|
|
223 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
224 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
225 |
</tr>
|
|
|
226 |
<tr>
|
|
|
227 |
<td width="80" rowspan="2" >RRRRRR<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
|
|
|
228 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
229 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
230 |
</tr>
|
|
|
231 |
<tr>
|
|
|
232 |
<td width="30" align="center">3.</td>
|
|
|
233 |
<td width="140">XXXX1<br />XXXX</td>
|
|
|
234 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
235 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
236 |
</tr>
|
|
|
237 |
<tr>
|
|
|
238 |
<td width="30" align="center">4.</td>
|
|
|
239 |
<td width="140">XXXX<br />XXXX</td>
|
|
|
240 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
241 |
<td width="80">XXXX<br />XXXX</td>
|
|
|
242 |
<td align="center" width="45">XXXX<br />XXXX</td>
|
|
|
243 |
</tr>
|
|
|
244 |
</table>
|
|
|
245 |
EOD;
|
|
|
246 |
|
|
|
247 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
248 |
|
|
|
249 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
250 |
|
|
|
251 |
// -----------------------------------------------------------------------------
|
|
|
252 |
|
|
|
253 |
// NON-BREAKING TABLE (nobr="true")
|
|
|
254 |
|
|
|
255 |
$tbl = <<<EOD
|
|
|
256 |
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
|
|
|
257 |
<tr>
|
|
|
258 |
<th colspan="3" align="center">NON-BREAKING TABLE</th>
|
|
|
259 |
</tr>
|
|
|
260 |
<tr>
|
|
|
261 |
<td>1-1</td>
|
|
|
262 |
<td>1-2</td>
|
|
|
263 |
<td>1-3</td>
|
|
|
264 |
</tr>
|
|
|
265 |
<tr>
|
|
|
266 |
<td>2-1</td>
|
|
|
267 |
<td>3-2</td>
|
|
|
268 |
<td>3-3</td>
|
|
|
269 |
</tr>
|
|
|
270 |
<tr>
|
|
|
271 |
<td>3-1</td>
|
|
|
272 |
<td>3-2</td>
|
|
|
273 |
<td>3-3</td>
|
|
|
274 |
</tr>
|
|
|
275 |
</table>
|
|
|
276 |
EOD;
|
|
|
277 |
|
|
|
278 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
279 |
|
|
|
280 |
// -----------------------------------------------------------------------------
|
|
|
281 |
|
|
|
282 |
// NON-BREAKING ROWS (nobr="true")
|
|
|
283 |
|
|
|
284 |
$tbl = <<<EOD
|
|
|
285 |
<table border="1" cellpadding="2" cellspacing="2" align="center">
|
|
|
286 |
<tr nobr="true">
|
|
|
287 |
<th colspan="3">NON-BREAKING ROWS</th>
|
|
|
288 |
</tr>
|
|
|
289 |
<tr nobr="true">
|
|
|
290 |
<td>ROW 1<br />COLUMN 1</td>
|
|
|
291 |
<td>ROW 1<br />COLUMN 2</td>
|
|
|
292 |
<td>ROW 1<br />COLUMN 3</td>
|
|
|
293 |
</tr>
|
|
|
294 |
<tr nobr="true">
|
|
|
295 |
<td>ROW 2<br />COLUMN 1</td>
|
|
|
296 |
<td>ROW 2<br />COLUMN 2</td>
|
|
|
297 |
<td>ROW 2<br />COLUMN 3</td>
|
|
|
298 |
</tr>
|
|
|
299 |
<tr nobr="true">
|
|
|
300 |
<td>ROW 3<br />COLUMN 1</td>
|
|
|
301 |
<td>ROW 3<br />COLUMN 2</td>
|
|
|
302 |
<td>ROW 3<br />COLUMN 3</td>
|
|
|
303 |
</tr>
|
|
|
304 |
</table>
|
|
|
305 |
EOD;
|
|
|
306 |
|
|
|
307 |
$pdf->writeHTML($tbl, true, false, false, false, '');
|
|
|
308 |
|
|
|
309 |
// -----------------------------------------------------------------------------
|
|
|
310 |
|
|
|
311 |
//Close and output PDF document
|
|
|
312 |
$pdf->Output('example_048.pdf', 'I');
|
|
|
313 |
|
|
|
314 |
//============================================================+
|
|
|
315 |
// END OF FILE
|
|
|
316 |
//============================================================+
|