example_027.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <?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. * Creates an example PDF TEST document using TCPDF
  20. * @package com.tecnick.tcpdf
  21. * @abstract TCPDF - Example: 1D Barcodes.
  22. * @author Nicola Asuni
  23. * @since 2008-03-04
  24. * @group barcode
  25. * @group pdf
  26. */
  27. // Include the main TCPDF library (search for installation path).
  28. require_once('tcpdf_include.php');
  29. // create new PDF document
  30. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  31. // set document information
  32. $pdf->setCreator(PDF_CREATOR);
  33. $pdf->setAuthor('Nicola Asuni');
  34. $pdf->setTitle('TCPDF Example 027');
  35. $pdf->setSubject('TCPDF Tutorial');
  36. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  37. // set default header data
  38. $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 027', PDF_HEADER_STRING);
  39. // set header and footer fonts
  40. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  41. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  42. // set default monospaced font
  43. $pdf->setDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  44. // set margins
  45. $pdf->setMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  46. $pdf->setHeaderMargin(PDF_MARGIN_HEADER);
  47. $pdf->setFooterMargin(PDF_MARGIN_FOOTER);
  48. // set auto page breaks
  49. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  50. // set image scale factor
  51. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  52. // set some language-dependent strings (optional)
  53. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  54. require_once(dirname(__FILE__).'/lang/eng.php');
  55. $pdf->setLanguageArray($l);
  56. }
  57. // ---------------------------------------------------------
  58. // set a barcode on the page footer
  59. $pdf->setBarcode(date('Y-m-d H:i:s'));
  60. // set font
  61. $pdf->setFont('helvetica', '', 11);
  62. // add a page
  63. $pdf->AddPage();
  64. // print a message
  65. $txt = "You can also export 1D barcodes in other formats (PNG, SVG, HTML). Check the examples inside the barcodes directory.\n";
  66. $pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
  67. $pdf->setY(30);
  68. // -----------------------------------------------------------------------------
  69. $pdf->setFont('helvetica', '', 10);
  70. // define barcode style
  71. $style = array(
  72. 'position' => '',
  73. 'align' => 'C',
  74. 'stretch' => false,
  75. 'fitwidth' => true,
  76. 'cellfitalign' => '',
  77. 'border' => true,
  78. 'hpadding' => 'auto',
  79. 'vpadding' => 'auto',
  80. 'fgcolor' => array(0,0,0),
  81. 'bgcolor' => false, //array(255,255,255),
  82. 'text' => true,
  83. 'font' => 'helvetica',
  84. 'fontsize' => 8,
  85. 'stretchtext' => 4
  86. );
  87. // PRINT VARIOUS 1D BARCODES
  88. // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  89. $pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
  90. $pdf->write1DBarcode('CODE 39', 'C39', '', '', '', 18, 0.4, $style, 'N');
  91. $pdf->Ln();
  92. // CODE 39 + CHECKSUM
  93. $pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
  94. $pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 18, 0.4, $style, 'N');
  95. $pdf->Ln();
  96. // CODE 39 EXTENDED
  97. $pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
  98. $pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
  99. $pdf->Ln();
  100. // CODE 39 EXTENDED + CHECKSUM
  101. $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
  102. $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', '', 18, 0.4, $style, 'N');
  103. $pdf->Ln();
  104. // CODE 93 - USS-93
  105. $pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
  106. $pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
  107. $pdf->Ln();
  108. // Standard 2 of 5
  109. $pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
  110. $pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
  111. $pdf->Ln();
  112. // Standard 2 of 5 + CHECKSUM
  113. $pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
  114. $pdf->write1DBarcode('1234567', 'S25+', '', '', '', 18, 0.4, $style, 'N');
  115. $pdf->Ln();
  116. // Interleaved 2 of 5
  117. $pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
  118. $pdf->write1DBarcode('1234567', 'I25', '', '', '', 18, 0.4, $style, 'N');
  119. $pdf->Ln();
  120. // Interleaved 2 of 5 + CHECKSUM
  121. $pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
  122. $pdf->write1DBarcode('1234567', 'I25+', '', '', '', 18, 0.4, $style, 'N');
  123. // add a page ----------
  124. $pdf->AddPage();
  125. // CODE 128 AUTO
  126. $pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
  127. $pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
  128. $pdf->Ln();
  129. // CODE 128 A
  130. $pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
  131. $pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
  132. $pdf->Ln();
  133. // CODE 128 B
  134. $pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
  135. $pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
  136. $pdf->Ln();
  137. // CODE 128 C
  138. $pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
  139. $pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
  140. $pdf->Ln();
  141. // EAN 8
  142. $pdf->Cell(0, 0, 'EAN 8', 0, 1);
  143. $pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
  144. $pdf->Ln();
  145. // EAN 13
  146. $pdf->Cell(0, 0, 'EAN 13', 0, 1);
  147. $pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
  148. $pdf->Ln();
  149. // UPC-A
  150. $pdf->Cell(0, 0, 'UPC-A', 0, 1);
  151. $pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
  152. $pdf->Ln();
  153. // UPC-E
  154. $pdf->Cell(0, 0, 'UPC-E', 0, 1);
  155. $pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
  156. // add a page ----------
  157. $pdf->AddPage();
  158. // 5-Digits UPC-Based Extension
  159. $pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
  160. $pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
  161. $pdf->Ln();
  162. // 2-Digits UPC-Based Extension
  163. $pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 0, 1);
  164. $pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
  165. $pdf->Ln();
  166. // MSI
  167. $pdf->Cell(0, 0, 'MSI', 0, 1);
  168. $pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
  169. $pdf->Ln();
  170. // MSI + CHECKSUM (module 11)
  171. $pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
  172. $pdf->write1DBarcode('80523', 'MSI+', '', '', '', 18, 0.4, $style, 'N');
  173. $pdf->Ln();
  174. // CODABAR
  175. $pdf->Cell(0, 0, 'CODABAR', 0, 1);
  176. $pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
  177. $pdf->Ln();
  178. // CODE 11
  179. $pdf->Cell(0, 0, 'CODE 11', 0, 1);
  180. $pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
  181. $pdf->Ln();
  182. // PHARMACODE
  183. $pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
  184. $pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
  185. $pdf->Ln();
  186. // PHARMACODE TWO-TRACKS
  187. $pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
  188. $pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
  189. // add a page ----------
  190. $pdf->AddPage();
  191. // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
  192. $pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
  193. $pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
  194. $pdf->Ln();
  195. // POSTNET
  196. $pdf->Cell(0, 0, 'POSTNET', 0, 1);
  197. $pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
  198. $pdf->Ln();
  199. // PLANET
  200. $pdf->Cell(0, 0, 'PLANET', 0, 1);
  201. $pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
  202. $pdf->Ln();
  203. // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  204. $pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
  205. $pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', '', 15, 0.6, $style, 'N');
  206. $pdf->Ln();
  207. // KIX (Klant index - Customer index)
  208. $pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
  209. $pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', '', 15, 0.6, $style, 'N');
  210. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  211. // TEST BARCODE ALIGNMENTS
  212. // add a page
  213. $pdf->AddPage();
  214. // set a background color
  215. $style['bgcolor'] = array(255,255,240);
  216. $style['fgcolor'] = array(127,0,0);
  217. // Left position
  218. $style['position'] = 'L';
  219. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  220. $pdf->Ln(2);
  221. // Center position
  222. $style['position'] = 'C';
  223. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  224. $pdf->Ln(2);
  225. // Right position
  226. $style['position'] = 'R';
  227. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  228. $pdf->Ln(2);
  229. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  230. $style['fgcolor'] = array(0,127,0);
  231. $style['position'] = '';
  232. $style['stretch'] = false; // disable stretch
  233. $style['fitwidth'] = false; // disable fitwidth
  234. // Left alignment
  235. $style['align'] = 'L';
  236. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  237. $pdf->Ln(2);
  238. // Center alignment
  239. $style['align'] = 'C';
  240. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  241. $pdf->Ln(2);
  242. // Right alignment
  243. $style['align'] = 'R';
  244. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  245. $pdf->Ln(2);
  246. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  247. $style['fgcolor'] = array(0,64,127);
  248. $style['position'] = '';
  249. $style['stretch'] = false; // disable stretch
  250. $style['fitwidth'] = true; // disable fitwidth
  251. // Left alignment
  252. $style['cellfitalign'] = 'L';
  253. $pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  254. $pdf->Ln(2);
  255. // Center alignment
  256. $style['cellfitalign'] = 'C';
  257. $pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  258. $pdf->Ln(2);
  259. // Right alignment
  260. $style['cellfitalign'] = 'R';
  261. $pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  262. $pdf->Ln(2);
  263. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  264. $style['fgcolor'] = array(127,0,127);
  265. // Left alignment
  266. $style['position'] = 'L';
  267. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  268. $pdf->Ln(2);
  269. // Center alignment
  270. $style['position'] = 'C';
  271. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  272. $pdf->Ln(2);
  273. // Right alignment
  274. $style['position'] = 'R';
  275. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  276. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  277. // TEST BARCODE STYLE
  278. // define barcode style
  279. $style = array(
  280. 'position' => '',
  281. 'align' => '',
  282. 'stretch' => true,
  283. 'fitwidth' => false,
  284. 'cellfitalign' => '',
  285. 'border' => true,
  286. 'hpadding' => 'auto',
  287. 'vpadding' => 'auto',
  288. 'fgcolor' => array(0,0,128),
  289. 'bgcolor' => array(255,255,128),
  290. 'text' => true,
  291. 'label' => 'CUSTOM LABEL',
  292. 'font' => 'helvetica',
  293. 'fontsize' => 8,
  294. 'stretchtext' => 4
  295. );
  296. // CODE 39 EXTENDED + CHECKSUM
  297. $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
  298. $pdf->setLineStyle(array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
  299. $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 120, 25, 0.4, $style, 'N');
  300. // ---------------------------------------------------------
  301. //Close and output PDF document
  302. $pdf->Output('example_027.pdf', 'I');
  303. //============================================================+
  304. // END OF FILE
  305. //============================================================+