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_061.php
4
// Begin       : 2010-05-24
5
// Last Update : 2010-08-08
6
//
7
// Description : Example 061 for TCPDF class
8
//               XHTML + CSS
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: XHTML + CSS
26
 * @author Nicola Asuni
27
 * @copyright 2004-2010 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 2010-05-25
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 061');
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.' 061', 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', '', 10);
74
 
75
// add a page
76
$pdf->AddPage();
77
 
78
/* NOTE:
79
 * *********************************************************
80
 * You can load external XHTML using :
81
 *
82
 * $html = file_get_contents('/path/to/your/file.html');
83
 *
84
 * External CSS files will be automatically loaded.
85
 * Sometimes you need to fix the path of the external CSS.
86
 * *********************************************************
87
 */
88
 
89
// define some HTML content with style
90
$html = <<<EOF
91
<!-- EXAMPLE OF CSS STYLE -->
92
<style>
93
	h1 {
94
		color: navy;
95
		font-family: times;
96
		font-size: 24pt;
97
		text-decoration: underline;
98
	}
99
	p.first {
100
		color: #003300;
101
		font-family: helvetica;
102
		font-size: 12pt;
103
	}
104
	p.first span {
105
		color: #006600;
106
		font-style: italic;
107
	}
108
	p#second {
109
		color: rgb(00,63,127);
110
		font-family: times;
111
		font-size: 12pt;
112
		text-align: justify;
113
	}
114
	p#second > span {
115
		background-color: #FFFFAA;
116
	}
117
	table.first {
118
		color: #003300;
119
		font-family: helvetica;
120
		font-size: 8pt;
121
		border-left: 3px solid red;
122
		border-right: 3px solid #FF00FF;
123
		border-top: 3px solid green;
124
		border-bottom: 3px solid blue;
125
		background-color: #ccffcc;
126
	}
127
	td {
128
		border: 2px solid blue;
129
		background-color: #ffffee;
130
	}
131
	td.second {
132
		border: 2px dashed green;
133
	}
134
	div.test {
135
		color: #CC0000;
136
		background-color: #FFFF66;
137
		font-family: helvetica;
138
		font-size: 10pt;
139
		border-style: solid solid solid solid;
140
		border-width: 2px 2px 2px 2px;
141
		border-color: green #FF00FF blue red;
142
		text-align: center;
143
	}
144
</style>
145
 
146
<h1 class="title">Example of <i style="color:#990000">XHTML + CSS</i></h1>
147
 
148
<p class="first">Example of paragraph with class selector. <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus. Phasellus quis velit velit, non condimentum quam. Sed neque urna, ultrices ac volutpat vel, laoreet vitae augue. Sed vel velit erat. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras eget velit nulla, eu sagittis elit. Nunc ac arcu est, in lobortis tellus. Praesent condimentum rhoncus sodales. In hac habitasse platea dictumst. Proin porta eros pharetra enim tincidunt dignissim nec vel dolor. Cras sapien elit, ornare ac dignissim eu, ultricies ac eros. Maecenas augue magna, ultrices a congue in, mollis eu nulla. Nunc venenatis massa at est eleifend faucibus. Vivamus sed risus lectus, nec interdum nunc.</span></p>
149
 
150
<p id="second">Example of paragraph with ID selector. <span>Fusce et felis vitae diam lobortis sollicitudin. Aenean tincidunt accumsan nisi, id vehicula quam laoreet elementum. Phasellus egestas interdum erat, et viverra ipsum ultricies ac. Praesent sagittis augue at augue volutpat eleifend. Cras nec orci neque. Mauris bibendum posuere blandit. Donec feugiat mollis dui sit amet pellentesque. Sed a enim justo. Donec tincidunt, nisl eget elementum aliquam, odio ipsum ultrices quam, eu porttitor ligula urna at lorem. Donec varius, eros et convallis laoreet, ligula tellus consequat felis, ut ornare metus tellus sodales velit. Duis sed diam ante. Ut rutrum malesuada massa, vitae consectetur ipsum rhoncus sed. Suspendisse potenti. Pellentesque a congue massa.</span></p>
151
 
152
<div class="test">example of DIV with border and fill.<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sed imperdiet lectus.</div>
153
 
154
<br />
155
 
156
<table class="first" cellpadding="4" cellspacing="6">
157
 <tr>
158
  <td width="30" align="center"><b>No.</b></td>
159
  <td width="140" align="center" bgcolor="#FFFF00"><b>XXXX</b></td>
160
  <td width="140" align="center"><b>XXXX</b></td>
161
  <td width="80" align="center"> <b>XXXX</b></td>
162
  <td width="80" align="center"><b>XXXX</b></td>
163
  <td width="45" align="center"><b>XXXX</b></td>
164
 </tr>
165
 <tr>
166
  <td width="30" align="center">1.</td>
167
  <td width="140" rowspan="6" class="second">XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
168
  <td width="140">XXXX<br />XXXX</td>
169
  <td width="80">XXXX<br />XXXX</td>
170
  <td width="80">XXXX</td>
171
  <td align="center" width="45">XXXX<br />XXXX</td>
172
 </tr>
173
 <tr>
174
  <td width="30" align="center" rowspan="3">2.</td>
175
  <td width="140" rowspan="3">XXXX<br />XXXX</td>
176
  <td width="80">XXXX<br />XXXX</td>
177
  <td width="80">XXXX<br />XXXX</td>
178
  <td align="center" width="45">XXXX<br />XXXX</td>
179
 </tr>
180
 <tr>
181
  <td width="80">XXXX<br />XXXX<br />XXXX<br />XXXX</td>
182
  <td width="80">XXXX<br />XXXX</td>
183
  <td align="center" width="45">XXXX<br />XXXX</td>
184
 </tr>
185
 <tr>
186
  <td width="80" rowspan="2" >XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
187
  <td width="80">XXXX<br />XXXX</td>
188
  <td align="center" width="45">XXXX<br />XXXX</td>
189
 </tr>
190
 <tr>
191
  <td width="30" align="center">3.</td>
192
  <td width="140">XXXX<br />XXXX</td>
193
  <td width="80">XXXX<br />XXXX</td>
194
  <td align="center" width="45">XXXX<br />XXXX</td>
195
 </tr>
196
 <tr bgcolor="#FFFF80">
197
  <td width="30" align="center">4.</td>
198
  <td width="140" bgcolor="#00CC00" color="#FFFF00">XXXX<br />XXXX</td>
199
  <td width="80">XXXX<br />XXXX</td>
200
  <td width="80">XXXX<br />XXXX</td>
201
  <td align="center" width="45">XXXX<br />XXXX</td>
202
 </tr>
203
</table>
204
EOF;
205
 
206
// output the HTML content
207
$pdf->writeHTML($html, true, false, true, false, '');
208
 
209
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
210
 
211
// *******************************************************************
212
// HTML TIPS & TRICKS
213
// *******************************************************************
214
 
215
// REMOVE CELL PADDING
216
//
217
// $pdf->SetCellPadding(0);
218
//
219
// This is used to remove any additional vertical space inside a
220
// single cell of text.
221
 
222
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223
 
224
// REMOVE TAG TOP AND BOTTOM MARGINS
225
//
226
// $tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)));
227
// $pdf->setHtmlVSpace($tagvs);
228
//
229
// Since the CSS margin command is not yet implemented on TCPDF, you
230
// need to set the spacing of block tags using the following method.
231
 
232
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233
 
234
// SET LINE HEIGHT
235
//
236
// $pdf->setCellHeightRatio(1.25);
237
//
238
// You can use the following method to fine tune the line height
239
// (the number is a percentage relative to font height).
240
 
241
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
242
 
243
// CHANGE THE PIXEL CONVERSION RATIO
244
//
245
// $pdf->setImageScale(0.47);
246
//
247
// This is used to adjust the conversion ratio between pixels and
248
// document units. Increase the value to get smaller objects.
249
// Since you are using pixel unit, this method is important to set the
250
// right zoom factor.
251
//
252
// Suppose that you want to print a web page larger 1024 pixels to
253
// fill all the available page width.
254
// An A4 page is larger 210mm equivalent to 8.268 inches, if you
255
// subtract 13mm (0.512") of margins for each side, the remaining
256
// space is 184mm (7.244 inches).
257
// The default resolution for a PDF document is 300 DPI (dots per
258
// inch), so you have 7.244 * 300 = 2173.2 dots (this is the maximum
259
// number of points you can print at 300 DPI for the given width).
260
// The conversion ratio is approximatively 1024 / 2173.2 = 0.47 px/dots
261
// If the web page is larger 1280 pixels, on the same A4 page the
262
// conversion ratio to use is 1280 / 2173.2 = 0.59 pixels/dots
263
 
264
// *******************************************************************
265
 
266
// reset pointer to the last page
267
$pdf->lastPage();
268
 
269
// ---------------------------------------------------------
270
 
271
//Close and output PDF document
272
$pdf->Output('example_061.pdf', 'I');
273
 
274
//============================================================+
275
// END OF FILE
276
//============================================================+