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_057.php
4
// Begin       : 2010-04-03
5
// Last Update : 2010-10-05
6
//
7
// Description : Example 057 for TCPDF class
8
//               Cell vertical alignments
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: Cell vertical alignments
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 057');
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.' 057', 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 alignment options for Cell()', '', 0, 'L', true, 0, false, false, 0);
79
 
80
$pdf->SetFont('helvetica', '', 11);
81
 
82
// set border width
83
$pdf->SetLineWidth(0.7);
84
 
85
// set color for cell border
86
$pdf->SetDrawColor(0,128,255);
87
 
88
$pdf->setCellHeightRatio(3);
89
 
90
$pdf->SetXY(15, 60);
91
 
92
// text on center
93
$pdf->Cell(30, 0, 'Top-Center', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'C');
94
$pdf->Cell(30, 0, 'Center-Center', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'C');
95
$pdf->Cell(30, 0, 'Bottom-Center', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'C');
96
$pdf->Cell(30, 0, 'Ascent-Center', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'C');
97
$pdf->Cell(30, 0, 'Baseline-Center', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'C');
98
$pdf->Cell(30, 0, 'Descent-Center', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'C');
99
 
100
 
101
$pdf->SetXY(15, 90);
102
 
103
// text on top
104
$pdf->Cell(30, 0, 'Top-Top', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'T');
105
$pdf->Cell(30, 0, 'Center-Top', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'T');
106
$pdf->Cell(30, 0, 'Bottom-Top', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'T');
107
$pdf->Cell(30, 0, 'Ascent-Top', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'T');
108
$pdf->Cell(30, 0, 'Baseline-Top', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'T');
109
$pdf->Cell(30, 0, 'Descent-Top', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'T');
110
 
111
 
112
$pdf->SetXY(15, 120);
113
 
114
// text on bottom
115
$pdf->Cell(30, 0, 'Top-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'B');
116
$pdf->Cell(30, 0, 'Center-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'B');
117
$pdf->Cell(30, 0, 'Bottom-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
118
$pdf->Cell(30, 0, 'Ascent-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'B');
119
$pdf->Cell(30, 0, 'Baseline-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'B');
120
$pdf->Cell(30, 0, 'Descent-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'B');
121
 
122
 
123
// draw some reference lines
124
$linestyle = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(255, 0, 0));
125
$pdf->Line(15, 60, 195, 60, $linestyle);
126
$pdf->Line(15, 90, 195, 90, $linestyle);
127
$pdf->Line(15, 120, 195, 120, $linestyle);
128
 
129
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130
 
131
// Print an image to explain cell measures
132
 
133
$pdf->Image('../images/tcpdf_cell.png', 15, 160, 100, 100, 'PNG', '', '', false, 300, '', false, false, 0, false, false, false);
134
$legend = 'LEGEND:
135
 
136
X: cell x top-left origin (top-right for RTL)
137
Y: cell y top-left origin (top-right for RTL)
138
CW: cell width
139
CH: cell height
140
LW: line width
141
NRL: normal line position
142
EXT: external line position
143
INT: internal line position
144
ML: margin left
145
MR: margin right
146
MT: margin top
147
MB: margin bottom
148
PL: padding left
149
PR: padding right
150
PT: padding top
151
PB: padding bottom
152
TW: text width
153
FA: font ascent
154
FB: font baseline
155
FD: font descent';
156
$pdf->SetFont('helvetica', '', 10);
157
$pdf->setCellHeightRatio(1.25);
158
$pdf->MultiCell(0, 0, $legend, 0, 'L', false, 1, 125, 160, true, 0, false, true, 0, 'T', false);
159
 
160
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161
 
162
// CELL BORDERS
163
 
164
// add a page
165
$pdf->AddPage();
166
 
167
$pdf->SetFont('helvetica', 'B', 20);
168
 
169
$pdf->Write(0, 'Example of borders for Cell()', '', 0, 'L', true, 0, false, false, 0);
170
 
171
$pdf->SetFont('helvetica', '', 11);
172
 
173
// set border width
174
$pdf->SetLineWidth(0.508);
175
 
176
// set color for cell border
177
$pdf->SetDrawColor(0,128,255);
178
 
179
// set filling color
180
$pdf->SetFillColor(255,255,128);
181
 
182
// set cell height ratio
183
$pdf->setCellHeightRatio(3);
184
 
185
$pdf->Cell(30, 0, '1', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
186
$pdf->Ln(2);
187
$pdf->Cell(30, 0, 'LTRB', 'LTRB', 1, 'C', 1, '', 0, false, 'T', 'C');
188
$pdf->Ln(2);
189
$pdf->Cell(30, 0, 'LTR', 'LTR', 1, 'C', 1, '', 0, false, 'T', 'C');
190
$pdf->Ln(2);
191
$pdf->Cell(30, 0, 'TRB', 'TRB', 1, 'C', 1, '', 0, false, 'T', 'C');
192
$pdf->Ln(2);
193
$pdf->Cell(30, 0, 'LRB', 'LRB', 1, 'C', 1, '', 0, false, 'T', 'C');
194
$pdf->Ln(2);
195
$pdf->Cell(30, 0, 'LTB', 'LTB', 1, 'C', 1, '', 0, false, 'T', 'C');
196
$pdf->Ln(2);
197
$pdf->Cell(30, 0, 'LT', 'LT', 1, 'C', 1, '', 0, false, 'T', 'C');
198
$pdf->Ln(2);
199
$pdf->Cell(30, 0, 'TR', 'TR', 1, 'C', 1, '', 0, false, 'T', 'C');
200
$pdf->Ln(2);
201
$pdf->Cell(30, 0, 'RB', 'RB', 1, 'C', 1, '', 0, false, 'T', 'C');
202
$pdf->Ln(2);
203
$pdf->Cell(30, 0, 'LB', 'LB', 1, 'C', 1, '', 0, false, 'T', 'C');
204
$pdf->Ln(2);
205
$pdf->Cell(30, 0, 'LR', 'LR', 1, 'C', 1, '', 0, false, 'T', 'C');
206
$pdf->Ln(2);
207
$pdf->Cell(30, 0, 'TB', 'TB', 1, 'C', 1, '', 0, false, 'T', 'C');
208
$pdf->Ln(2);
209
$pdf->Cell(30, 0, 'L', 'L', 1, 'C', 1, '', 0, false, 'T', 'C');
210
$pdf->Ln(2);
211
$pdf->Cell(30, 0, 'T', 'T', 1, 'C', 1, '', 0, false, 'T', 'C');
212
$pdf->Ln(2);
213
$pdf->Cell(30, 0, 'R', 'R', 1, 'C', 1, '', 0, false, 'T', 'C');
214
$pdf->Ln(2);
215
$pdf->Cell(30, 0, 'B', 'B', 1, 'C', 1, '', 0, false, 'T', 'C');
216
 
217
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218
 
219
// ADVANCED SETTINGS FOR CELL BORDERS
220
 
221
// add a page
222
$pdf->AddPage();
223
 
224
$pdf->SetFont('helvetica', 'B', 20);
225
 
226
$pdf->Write(0, 'Example of advanced border settings for Cell()', '', 0, 'L', true, 0, false, false, 0);
227
 
228
$pdf->SetFont('helvetica', '', 11);
229
 
230
// set border width
231
$pdf->SetLineWidth(1);
232
 
233
// set color for cell border
234
$pdf->SetDrawColor(0,128,255);
235
 
236
// set filling color
237
$pdf->SetFillColor(255,255,128);
238
 
239
$border = array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
240
$pdf->Cell(30, 0, 'LTRB', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
241
$pdf->Ln(5);
242
 
243
$border = array(
244
'L' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)),
245
'R' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 255)),
246
'T' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 255, 0)),
247
'B' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 255)));
248
$pdf->Cell(30, 0, 'LTRB', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
249
$pdf->Ln(5);
250
 
251
$border = array('mode' => 'ext', 'LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
252
$pdf->Cell(30, 0, 'LTRB EXT', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
253
$pdf->Ln(5);
254
 
255
$border = array('mode' => 'int', 'LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
256
$pdf->Cell(30, 0, 'LTRB INT', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
257
$pdf->Ln(5);
258
 
259
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
260
 
261
// reset pointer to the last page
262
$pdf->lastPage();
263
 
264
// ---------------------------------------------------------
265
 
266
//Close and output PDF document
267
$pdf->Output('example_057.pdf', 'I');
268
 
269
//============================================================+
270
// END OF FILE
271
//============================================================+