example_027.php 10 KB

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