Subversion Repositories Applications.annuaire

Rev

Rev 296 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
296 aurelien 1
<?php
2
//============================================================+
3
// File name   : example_006.php
4
// Begin       : 2008-03-04
5
// Last Update : 2010-11-20
6
//
7
// Description : Example 006 for TCPDF class
8
//               WriteHTML and RTL support
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: WriteHTML and RTL support
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 2008-03-04
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 006');
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.' 006', 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('dejavusans', '', 10);
74
 
75
// add a page
76
$pdf->AddPage();
77
 
78
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
79
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
80
 
81
// create some HTML content
82
$html = '<h1>HTML Example</h1>
83
Some special characters: &lt; € &euro; &#8364; &amp; è &egrave; &copy; &gt; \\slash \\\\double-slash \\\\\\triple-slash
84
<h2>List</h2>
85
List example:
86
<ol>
87
	<li><img src="../images/logo_example.png" alt="test alt attribute" width="30" height="30" border="0" /> test image</li>
88
	<li><b>bold text</b></li>
89
	<li><i>italic text</i></li>
90
	<li><u>underlined text</u></li>
91
	<li><b>b<i>bi<u>biu</u>bi</i>b</b></li>
92
	<li><a href="http://www.tecnick.com" dir="ltr">link to http://www.tecnick.com</a></li>
93
	<li>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.<br />Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.</li>
94
	<li>SUBLIST
95
		<ol>
96
			<li>row one
97
				<ul>
98
					<li>sublist</li>
99
				</ul>
100
			</li>
101
			<li>row two</li>
102
		</ol>
103
	</li>
104
	<li><b>T</b>E<i>S</i><u>T</u> <del>line through</del></li>
105
	<li><font size="+3">font + 3</font></li>
106
	<li><small>small text</small> normal <small>small text</small> normal <sub>subscript</sub> normal <sup>superscript</sup> normal</li>
107
</ol>
108
<dl>
109
	<dt>Coffee</dt>
110
	<dd>Black hot drink</dd>
111
	<dt>Milk</dt>
112
	<dd>White cold drink</dd>
113
</dl>
114
<div style="text-align:center">IMAGES<br />
115
<img src="../images/logo_example.png" alt="test alt attribute" width="100" height="100" border="0" /><img src="../images/tiger.ai" alt="test alt attribute" width="100" height="100" border="0" /><img src="../images/logo_example.jpg" alt="test alt attribute" width="100" height="100" border="0" />
116
</div>';
117
 
118
// output the HTML content
119
$pdf->writeHTML($html, true, false, true, false, '');
120
 
121
 
122
// output some RTL HTML content
123
$html = '<div style="text-align:center">The words &#8220;<span dir="rtl">&#1502;&#1494;&#1500; [mazel] &#1496;&#1493;&#1489; [tov]</span>&#8221; mean &#8220;Congratulations!&#8221;</div>';
124
$pdf->writeHTML($html, true, false, true, false, '');
125
 
126
// test some inline CSS
127
$html = '<p>This is just an example of html code to demonstrate some supported CSS inline styles.
128
<span style="font-weight: bold;">bold text</span>
129
<span style="text-decoration: line-through;">line-trough</span>
130
<span style="text-decoration: underline line-through;">underline and line-trough</span>
131
<span style="color: rgb(0, 128, 64);">color</span>
132
<span style="background-color: rgb(255, 0, 0); color: rgb(255, 255, 255);">background color</span>
133
<span style="font-weight: bold;">bold</span>
134
<span style="font-size: xx-small;">xx-small</span>
135
<span style="font-size: x-small;">x-small</span>
136
<span style="font-size: small;">small</span>
137
<span style="font-size: medium;">medium</span>
138
<span style="font-size: large;">large</span>
139
<span style="font-size: x-large;">x-large</span>
140
<span style="font-size: xx-large;">xx-large</span>
141
</p>';
142
 
143
$pdf->writeHTML($html, true, false, true, false, '');
144
 
145
// reset pointer to the last page
146
$pdf->lastPage();
147
 
148
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
149
// Print a table
150
 
151
// add a page
152
$pdf->AddPage();
153
 
154
// create some HTML content
155
$subtable = '<table border="1" cellspacing="6" cellpadding="4"><tr><td>a</td><td>b</td></tr><tr><td>c</td><td>d</td></tr></table>';
156
 
157
$html = '<h2>HTML TABLE:</h2>
158
<table border="1" cellspacing="3" cellpadding="4">
159
	<tr>
160
		<th>#</th>
161
		<th align="right">RIGHT align</th>
162
		<th align="left">LEFT align</th>
163
		<th>4A</th>
164
	</tr>
165
	<tr>
166
		<td>1</td>
167
		<td bgcolor="#cccccc" align="center" colspan="2">A1 ex<i>amp</i>le <a href="http://www.tcpdf.org">link</a> column span. One two tree four five six seven eight nine ten.<br />line after br<br /><small>small text</small> normal <sub>subscript</sub> normal <sup>superscript</sup> normal  bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla<ol><li>first<ol><li>sublist</li><li>sublist</li></ol></li><li>second</li></ol><small color="#FF0000" bgcolor="#FFFF00">small small small small small small small small small small small small small small small small small small small small</small></td>
168
		<td>4B</td>
169
	</tr>
170
	<tr>
171
		<td>'.$subtable.'</td>
172
		<td bgcolor="#0000FF" color="yellow" align="center">A2 € &euro; &#8364; &amp; è &egrave;<br/>A2 € &euro; &#8364; &amp; è &egrave;</td>
173
		<td bgcolor="#FFFF00" align="left"><font color="#FF0000">Red</font> Yellow BG</td>
174
		<td>4C</td>
175
	</tr>
176
	<tr>
177
		<td>1A</td>
178
		<td rowspan="2" colspan="2" bgcolor="#FFFFCC">2AA<br />2AB<br />2AC</td>
179
		<td bgcolor="#FF0000">4D</td>
180
	</tr>
181
	<tr>
182
		<td>1B</td>
183
		<td>4E</td>
184
	</tr>
185
	<tr>
186
		<td>1C</td>
187
		<td>2C</td>
188
		<td>3C</td>
189
		<td>4F</td>
190
	</tr>
191
</table>';
192
 
193
// output the HTML content
194
$pdf->writeHTML($html, true, false, true, false, '');
195
 
196
// Print some HTML Cells
197
 
198
$html = '<span color="red">red</span> <span color="green">green</span> <span color="blue">blue</span><br /><span color="red">red</span> <span color="green">green</span> <span color="blue">blue</span>';
199
 
200
$pdf->SetFillColor(255,255,0);
201
 
202
$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'L', true);
203
$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 1, true, 'C', true);
204
$pdf->writeHTMLCell(0, 0, '', '', $html, 'LRTB', 1, 0, true, 'R', true);
205
 
206
// reset pointer to the last page
207
$pdf->lastPage();
208
 
209
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210
// Print a table
211
 
212
// add a page
213
$pdf->AddPage();
214
 
215
// create some HTML content
216
$html = '<h1>Image alignments on HTML table</h1>
217
<table cellpadding="1" cellspacing="1" border="1" style="text-align:center;">
218
<tr><td><img src="../images/logo_example.png" border="0" height="41" width="41" /></td></tr>
219
<tr style="text-align:left;"><td><img src="../images/logo_example.png" border="0" height="41" width="41" align="top" /></td></tr>
220
<tr style="text-align:center;"><td><img src="../images/logo_example.png" border="0" height="41" width="41" align="middle" /></td></tr>
221
<tr style="text-align:right;"><td><img src="../images/logo_example.png" border="0" height="41" width="41" align="bottom" /></td></tr>
222
<tr><td style="text-align:left;"><img src="../images/logo_example.png" border="0" height="41" width="41" align="top" /></td></tr>
223
<tr><td style="text-align:center;"><img src="../images/logo_example.png" border="0" height="41" width="41" align="middle" /></td></tr>
224
<tr><td style="text-align:right;"><img src="../images/logo_example.png" border="0" height="41" width="41" align="bottom" /></td></tr>
225
</table>';
226
 
227
// output the HTML content
228
$pdf->writeHTML($html, true, false, true, false, '');
229
 
230
// reset pointer to the last page
231
$pdf->lastPage();
232
 
233
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234
// Print all HTML colors
235
 
236
// add a page
237
$pdf->AddPage();
238
 
239
require('../htmlcolors.php');
240
 
241
$textcolors = '<h1>HTML Text Colors</h1>';
242
$bgcolors = '<hr /><h1>HTML Background Colors</h1>';
243
 
244
foreach($webcolor as $k => $v) {
245
	$textcolors .= '<span color="#'.$v.'">'.$v.'</span> ';
246
	$bgcolors .= '<span bgcolor="#'.$v.'" color="#333333">'.$v.'</span> ';
247
}
248
 
249
// output the HTML content
250
$pdf->writeHTML($textcolors, true, false, true, false, '');
251
$pdf->writeHTML($bgcolors, true, false, true, false, '');
252
 
253
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
254
 
255
// Test word-wrap
256
 
257
// create some HTML content
258
$html = '<hr />
259
<h1>Various tests</h1>
260
<a href="#2">link to page 2</a><br />
261
<font face="courier"><b>thisisaverylongword</b></font> <font face="helvetica"><i>thisisanotherverylongword</i></font> <font face="times"><b>thisisaverylongword</b></font> thisisanotherverylongword <font face="times">thisisaverylongword</font> <font face="courier"><b>thisisaverylongword</b></font> <font face="helvetica"><i>thisisanotherverylongword</i></font> <font face="times"><b>thisisaverylongword</b></font> thisisanotherverylongword <font face="times">thisisaverylongword</font> <font face="courier"><b>thisisaverylongword</b></font> <font face="helvetica"><i>thisisanotherverylongword</i></font> <font face="times"><b>thisisaverylongword</b></font> thisisanotherverylongword <font face="times">thisisaverylongword</font> <font face="courier"><b>thisisaverylongword</b></font> <font face="helvetica"><i>thisisanotherverylongword</i></font> <font face="times"><b>thisisaverylongword</b></font> thisisanotherverylongword <font face="times">thisisaverylongword</font> <font face="courier"><b>thisisaverylongword</b></font> <font face="helvetica"><i>thisisanotherverylongword</i></font> <font face="times"><b>thisisaverylongword</b></font> thisisanotherverylongword <font face="times">thisisaverylongword</font>';
262
 
263
// output the HTML content
264
$pdf->writeHTML($html, true, false, true, false, '');
265
 
266
// Test fonts nesting
267
$html1 = 'Default <font face="courier">Courier <font face="helvetica">Helvetica <font face="times">Times <font face="dejavusans">dejavusans </font>Times </font>Helvetica </font>Courier </font>Default';
268
$html2 = '<small>small text</small> normal <small>small text</small> normal <sub>subscript</sub> normal <sup>superscript</sup> normal';
269
$html3 = '<font size="10" color="#ff7f50">The</font> <font size="10" color="#6495ed">quick</font> <font size="14" color="#dc143c">brown</font> <font size="18" color="#008000">fox</font> <font size="22"><a href="http://www.tcpdf.org">jumps</a></font> <font size="22" color="#a0522d">over</font> <font size="18" color="#da70d6">the</font> <font size="14" color="#9400d3">lazy</font> <font size="10" color="#4169el">dog</font>.';
270
 
271
$html = $html1.'<br />'.$html2.'<br />'.$html3.'<br />'.$html3.'<br />'.$html2;
272
 
273
// output the HTML content
274
$pdf->writeHTML($html, true, false, true, false, '');
275
 
276
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
277
// test pre tag
278
 
279
// add a page
280
$pdf->AddPage();
281
 
282
$html = <<<EOF
283
<div style="background-color:#880000;color:white;">
284
Hello World!<br />
285
Hello
286
</div>
287
<pre style="background-color:#336699;color:white;">
288
int main() {
289
    printf("HelloWorld");
290
    return 0;
291
}
292
</pre>
293
<tt>Monospace font</tt>, normal font, <tt>monospace font</tt>, normal font.
294
<br />
295
<div style="background-color:#880000;color:white;">DIV LEVEL 1<div style="background-color:#008800;color:white;">DIV LEVEL 2</div>DIV LEVEL 1</div>
296
<br />
297
<span style="background-color:#880000;color:white;">SPAN LEVEL 1 <span style="background-color:#008800;color:white;">SPAN LEVEL 2</span> SPAN LEVEL 1</span>
298
EOF;
299
 
300
// output the HTML content
301
$pdf->writeHTML($html, true, false, true, false, '');
302
 
303
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
304
 
305
// test custom bullet points for list
306
 
307
// add a page
308
$pdf->AddPage();
309
 
310
$html = <<<EOF
311
<h1>Test custom bullet image for list items</h1>
312
<ul style="font-size:14pt;list-style-type:img|png|4|4|../images/logo_example.png">
313
	<li>test custom bullet image</li>
314
	<li>test custom bullet image</li>
315
	<li>test custom bullet image</li>
316
	<li>test custom bullet image</li>
317
<ul>
318
EOF;
319
 
320
// output the HTML content
321
$pdf->writeHTML($html, true, false, true, false, '');
322
 
323
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
324
 
325
// reset pointer to the last page
326
$pdf->lastPage();
327
 
328
// ---------------------------------------------------------
329
 
330
//Close and output PDF document
331
$pdf->Output('example_006.pdf', 'I');
332
 
333
//============================================================+
334
// END OF FILE
335
//============================================================+