source: trunk/client/inc/hpdf5/tecnickcom/tcpdf/examples/example_048.php@ 394

Last change on this file since 394 was 347, checked in by roby, 3 years ago

Aggiornamento per compatibilità con php7.4

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