Projet

Général

Profil

Paste
Télécharger (11 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / libraries / tcpdf-6.2.9 / examples / example_027.php @ 7fe061e8

1 85ad3d82 Assos Assos
<?php
2
//============================================================+
3
// File name   : example_027.php
4
// Begin       : 2008-03-04
5
// Last Update : 2013-05-14
6
//
7
// Description : Example 027 for TCPDF class
8
//               1D Barcodes
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: 1D Barcodes.
23
 * @author Nicola Asuni
24
 * @since 2008-03-04
25
 */
26
27
// Include the main TCPDF library (search for installation path).
28
require_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 027');
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.' 027', 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)
62
if (@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 a barcode on the page footer
70
$pdf->setBarcode(date('Y-m-d H:i:s'));
71
72
// set font
73
$pdf->SetFont('helvetica', '', 11);
74
75
// add a page
76
$pdf->AddPage();
77
78
// print a message
79
$txt = "You can also export 1D barcodes in other formats (PNG, SVG, HTML). Check the examples inside the barcodes directory.\n";
80
$pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
81
$pdf->SetY(30);
82
83
// -----------------------------------------------------------------------------
84
85
$pdf->SetFont('helvetica', '', 10);
86
87
// define barcode style
88
$style = array(
89
        'position' => '',
90
        'align' => 'C',
91
        'stretch' => false,
92
        'fitwidth' => true,
93
        'cellfitalign' => '',
94
        'border' => true,
95
        'hpadding' => 'auto',
96
        'vpadding' => 'auto',
97
        'fgcolor' => array(0,0,0),
98
        'bgcolor' => false, //array(255,255,255),
99
        'text' => true,
100
        'font' => 'helvetica',
101
        'fontsize' => 8,
102
        'stretchtext' => 4
103
);
104
105
// PRINT VARIOUS 1D BARCODES
106
107
// CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
108
$pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
109
$pdf->write1DBarcode('CODE 39', 'C39', '', '', '', 18, 0.4, $style, 'N');
110
111
$pdf->Ln();
112
113
// CODE 39 + CHECKSUM
114
$pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
115
$pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 18, 0.4, $style, 'N');
116
117
$pdf->Ln();
118
119
// CODE 39 EXTENDED
120
$pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
121
$pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
122
123
$pdf->Ln();
124
125
// CODE 39 EXTENDED + CHECKSUM
126
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
127
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', '', 18, 0.4, $style, 'N');
128
129
$pdf->Ln();
130
131
// CODE 93 - USS-93
132
$pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
133
$pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
134
135
$pdf->Ln();
136
137
// Standard 2 of 5
138
$pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
139
$pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
140
141
$pdf->Ln();
142
143
// Standard 2 of 5 + CHECKSUM
144
$pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
145
$pdf->write1DBarcode('1234567', 'S25+', '', '', '', 18, 0.4, $style, 'N');
146
147
$pdf->Ln();
148
149
// Interleaved 2 of 5
150
$pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
151
$pdf->write1DBarcode('1234567', 'I25', '', '', '', 18, 0.4, $style, 'N');
152
153
$pdf->Ln();
154
155
// Interleaved 2 of 5 + CHECKSUM
156
$pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
157
$pdf->write1DBarcode('1234567', 'I25+', '', '', '', 18, 0.4, $style, 'N');
158
159
160
// add a page ----------
161
$pdf->AddPage();
162
163
// CODE 128 AUTO
164
$pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
165
$pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
166
167
$pdf->Ln();
168
169
// CODE 128 A
170
$pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
171
$pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
172
173
$pdf->Ln();
174
175
// CODE 128 B
176
$pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
177
$pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
178
179
$pdf->Ln();
180
181
// CODE 128 C
182
$pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
183
$pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
184
185
$pdf->Ln();
186
187
// EAN 8
188
$pdf->Cell(0, 0, 'EAN 8', 0, 1);
189
$pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
190
191
$pdf->Ln();
192
193
// EAN 13
194
$pdf->Cell(0, 0, 'EAN 13', 0, 1);
195
$pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
196
197
$pdf->Ln();
198
199
// UPC-A
200
$pdf->Cell(0, 0, 'UPC-A', 0, 1);
201
$pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
202
203
$pdf->Ln();
204
205
// UPC-E
206
$pdf->Cell(0, 0, 'UPC-E', 0, 1);
207
$pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
208
209
// add a page ----------
210
$pdf->AddPage();
211
212 c3ebc5b9 Assos Assos
// 5-Digits UPC-Based Extension
213
$pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
214 85ad3d82 Assos Assos
$pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
215
216
$pdf->Ln();
217
218 c3ebc5b9 Assos Assos
// 2-Digits UPC-Based Extension
219
$pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 0, 1);
220 85ad3d82 Assos Assos
$pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
221
222
$pdf->Ln();
223
224
// MSI
225
$pdf->Cell(0, 0, 'MSI', 0, 1);
226
$pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
227
228
$pdf->Ln();
229
230
// MSI + CHECKSUM (module 11)
231
$pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
232
$pdf->write1DBarcode('80523', 'MSI+', '', '', '', 18, 0.4, $style, 'N');
233
234
$pdf->Ln();
235
236
// CODABAR
237
$pdf->Cell(0, 0, 'CODABAR', 0, 1);
238
$pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
239
240
$pdf->Ln();
241
242
// CODE 11
243
$pdf->Cell(0, 0, 'CODE 11', 0, 1);
244
$pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
245
246
$pdf->Ln();
247
248
// PHARMACODE
249
$pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
250
$pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
251
252
$pdf->Ln();
253
254
// PHARMACODE TWO-TRACKS
255
$pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
256
$pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
257
258
// add a page ----------
259
$pdf->AddPage();
260
261
// IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
262
$pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
263
$pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
264
265
$pdf->Ln();
266
267
// POSTNET
268
$pdf->Cell(0, 0, 'POSTNET', 0, 1);
269
$pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
270
271
$pdf->Ln();
272
273
// PLANET
274
$pdf->Cell(0, 0, 'PLANET', 0, 1);
275
$pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
276
277
$pdf->Ln();
278
279
// RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
280
$pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
281
$pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', '', 15, 0.6, $style, 'N');
282
283
$pdf->Ln();
284
285
// KIX (Klant index - Customer index)
286
$pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
287
$pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', '', 15, 0.6, $style, 'N');
288
289
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
290
// TEST BARCODE ALIGNMENTS
291
292
// add a page
293
$pdf->AddPage();
294
295
// set a background color
296
$style['bgcolor'] = array(255,255,240);
297
$style['fgcolor'] = array(127,0,0);
298
299
// Left position
300
$style['position'] = 'L';
301
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
302
303
$pdf->Ln(2);
304
305
// Center position
306
$style['position'] = 'C';
307
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
308
309
$pdf->Ln(2);
310
311
// Right position
312
$style['position'] = 'R';
313
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
314
315
$pdf->Ln(2);
316
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
317
318
$style['fgcolor'] = array(0,127,0);
319
$style['position'] = '';
320
$style['stretch'] = false; // disable stretch
321
$style['fitwidth'] = false; // disable fitwidth
322
323
// Left alignment
324
$style['align'] = 'L';
325
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
326
327
$pdf->Ln(2);
328
329
// Center alignment
330
$style['align'] = 'C';
331
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
332
333
$pdf->Ln(2);
334
335
// Right alignment
336
$style['align'] = 'R';
337
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
338
339
$pdf->Ln(2);
340
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
341
342
$style['fgcolor'] = array(0,64,127);
343
$style['position'] = '';
344
$style['stretch'] = false; // disable stretch
345
$style['fitwidth'] = true; // disable fitwidth
346
347
// Left alignment
348
$style['cellfitalign'] = 'L';
349
$pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
350
351
$pdf->Ln(2);
352
353
// Center alignment
354
$style['cellfitalign'] = 'C';
355
$pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
356
357
$pdf->Ln(2);
358
359
// Right alignment
360
$style['cellfitalign'] = 'R';
361
$pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
362
363
$pdf->Ln(2);
364
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
365
366
$style['fgcolor'] = array(127,0,127);
367
368
// Left alignment
369
$style['position'] = 'L';
370
$pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
371
372
$pdf->Ln(2);
373
374
// Center alignment
375
$style['position'] = 'C';
376
$pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
377
378
$pdf->Ln(2);
379
380
// Right alignment
381
$style['position'] = 'R';
382
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
383
384
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
385
// TEST BARCODE STYLE
386
387
// define barcode style
388
$style = array(
389
        'position' => '',
390
        'align' => '',
391
        'stretch' => true,
392
        'fitwidth' => false,
393
        'cellfitalign' => '',
394
        'border' => true,
395
        'hpadding' => 'auto',
396
        'vpadding' => 'auto',
397
        'fgcolor' => array(0,0,128),
398
        'bgcolor' => array(255,255,128),
399
        'text' => true,
400
        'label' => 'CUSTOM LABEL',
401
        'font' => 'helvetica',
402
        'fontsize' => 8,
403
        'stretchtext' => 4
404
);
405
406
// CODE 39 EXTENDED + CHECKSUM
407
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
408
$pdf->SetLineStyle(array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
409
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 120, 25, 0.4, $style, 'N');
410
411
// ---------------------------------------------------------
412
413
//Close and output PDF document
414
$pdf->Output('example_027.pdf', 'I');
415
416
//============================================================+
417
// END OF FILE
418
//============================================================+