2 //============================================================+
3 // File name : example_027.php
5 // Last Update : 2013-05-14
7 // Description : Example 027 for TCPDF class
10 // Author: Nicola Asuni
17 //============================================================+
20 * Creates an example PDF TEST document using TCPDF
21 * @package com.tecnick.tcpdf
22 * @abstract TCPDF - Example: 1D Barcodes.
23 * @author Nicola Asuni
27 // Include the main TCPDF library (search for installation path).
28 require_once('tcpdf_include.php');
30 // create new PDF document
31 $pdf = new TCPDF(PDF_PAGE_ORIENTATION
, PDF_UNIT
, PDF_PAGE_FORMAT
, true, 'UTF-8', false);
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');
40 // set default header data
41 $pdf->SetHeaderData(PDF_HEADER_LOGO
, PDF_HEADER_LOGO_WIDTH
, PDF_HEADER_TITLE
.' 027', PDF_HEADER_STRING
);
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
));
47 // set default monospaced font
48 $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED
);
51 $pdf->SetMargins(PDF_MARGIN_LEFT
, PDF_MARGIN_TOP
, PDF_MARGIN_RIGHT
);
52 $pdf->SetHeaderMargin(PDF_MARGIN_HEADER
);
53 $pdf->SetFooterMargin(PDF_MARGIN_FOOTER
);
55 // set auto page breaks
56 $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM
);
58 // set image scale factor
59 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO
);
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);
67 // ---------------------------------------------------------
69 // set a barcode on the page footer
70 $pdf->setBarcode(date('Y-m-d H:i:s'));
73 $pdf->SetFont('helvetica', '', 11);
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);
83 // -----------------------------------------------------------------------------
85 $pdf->SetFont('helvetica', '', 10);
87 // define barcode style
97 'fgcolor' => array(0,0,0),
98 'bgcolor' => false, //array(255,255,255),
100 'font' => 'helvetica',
105 // PRINT VARIOUS 1D BARCODES
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');
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');
120 $pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
121 $pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
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');
132 $pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
133 $pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
138 $pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
139 $pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
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');
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');
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');
160 // add a page ----------
164 $pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
165 $pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
170 $pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
171 $pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
176 $pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
177 $pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
182 $pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
183 $pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
188 $pdf->Cell(0, 0, 'EAN 8', 0, 1);
189 $pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
194 $pdf->Cell(0, 0, 'EAN 13', 0, 1);
195 $pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
200 $pdf->Cell(0, 0, 'UPC-A', 0, 1);
201 $pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
206 $pdf->Cell(0, 0, 'UPC-E', 0, 1);
207 $pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
209 // add a page ----------
212 // 5-Digits UPC-Based Extension
213 $pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
214 $pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
218 // 2-Digits UPC-Based Extension
219 $pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 0, 1);
220 $pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
225 $pdf->Cell(0, 0, 'MSI', 0, 1);
226 $pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
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');
237 $pdf->Cell(0, 0, 'CODABAR', 0, 1);
238 $pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
243 $pdf->Cell(0, 0, 'CODE 11', 0, 1);
244 $pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
249 $pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
250 $pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
254 // PHARMACODE TWO-TRACKS
255 $pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
256 $pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
258 // add a page ----------
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');
268 $pdf->Cell(0, 0, 'POSTNET', 0, 1);
269 $pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
274 $pdf->Cell(0, 0, 'PLANET', 0, 1);
275 $pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
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');
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');
289 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
290 // TEST BARCODE ALIGNMENTS
295 // set a background color
296 $style['bgcolor'] = array(255,255,240);
297 $style['fgcolor'] = array(127,0,0);
300 $style['position'] = 'L';
301 $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
306 $style['position'] = 'C';
307 $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
312 $style['position'] = 'R';
313 $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
316 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
318 $style['fgcolor'] = array(0,127,0);
319 $style['position'] = '';
320 $style['stretch'] = false; // disable stretch
321 $style['fitwidth'] = false; // disable fitwidth
324 $style['align'] = 'L';
325 $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
330 $style['align'] = 'C';
331 $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
336 $style['align'] = 'R';
337 $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
340 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
342 $style['fgcolor'] = array(0,64,127);
343 $style['position'] = '';
344 $style['stretch'] = false; // disable stretch
345 $style['fitwidth'] = true; // disable fitwidth
348 $style['cellfitalign'] = 'L';
349 $pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
354 $style['cellfitalign'] = 'C';
355 $pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
360 $style['cellfitalign'] = 'R';
361 $pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
364 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
366 $style['fgcolor'] = array(127,0,127);
369 $style['position'] = 'L';
370 $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
375 $style['position'] = 'C';
376 $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
381 $style['position'] = 'R';
382 $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
384 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
385 // TEST BARCODE STYLE
387 // define barcode style
393 'cellfitalign' => '',
395 'hpadding' => 'auto',
396 'vpadding' => 'auto',
397 'fgcolor' => array(0,0,128),
398 'bgcolor' => array(255,255,128),
400 'label' => 'CUSTOM LABEL',
401 'font' => 'helvetica',
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');
411 // ---------------------------------------------------------
413 //Close and output PDF document
414 $pdf->Output('example_027.pdf', 'I');
416 //============================================================+
418 //============================================================+