example_027.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?php
  2. //============================================================+
  3. // File name : example_027.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2011-09-22
  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', '', 11);
  60. // add a page
  61. $pdf->AddPage();
  62. // print a message
  63. $txt = "You can also export 1D barcodes in other formats (PNG, SVG, HTML). Check the source code documentation of TCPDFBarcode class for further information.";
  64. $pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
  65. $pdf->SetY(30);
  66. // -----------------------------------------------------------------------------
  67. $pdf->SetFont('helvetica', '', 10);
  68. // define barcode style
  69. $style = array(
  70. 'position' => '',
  71. 'align' => 'C',
  72. 'stretch' => false,
  73. 'fitwidth' => true,
  74. 'cellfitalign' => '',
  75. 'border' => true,
  76. 'hpadding' => 'auto',
  77. 'vpadding' => 'auto',
  78. 'fgcolor' => array(0,0,0),
  79. 'bgcolor' => false, //array(255,255,255),
  80. 'text' => true,
  81. 'font' => 'helvetica',
  82. 'fontsize' => 8,
  83. 'stretchtext' => 4
  84. );
  85. // PRINT VARIOUS 1D BARCODES
  86. // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
  87. $pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
  88. $pdf->write1DBarcode('CODE 39', 'C39', '', '', '', 18, 0.4, $style, 'N');
  89. $pdf->Ln();
  90. // CODE 39 + CHECKSUM
  91. $pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
  92. $pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', '', 18, 0.4, $style, 'N');
  93. $pdf->Ln();
  94. // CODE 39 EXTENDED
  95. $pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
  96. $pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', '', 18, 0.4, $style, 'N');
  97. $pdf->Ln();
  98. // CODE 39 EXTENDED + CHECKSUM
  99. $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
  100. $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', '', 18, 0.4, $style, 'N');
  101. $pdf->Ln();
  102. // CODE 93 - USS-93
  103. $pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
  104. $pdf->write1DBarcode('TEST93', 'C93', '', '', '', 18, 0.4, $style, 'N');
  105. $pdf->Ln();
  106. // Standard 2 of 5
  107. $pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
  108. $pdf->write1DBarcode('1234567', 'S25', '', '', '', 18, 0.4, $style, 'N');
  109. $pdf->Ln();
  110. // Standard 2 of 5 + CHECKSUM
  111. $pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
  112. $pdf->write1DBarcode('1234567', 'S25+', '', '', '', 18, 0.4, $style, 'N');
  113. $pdf->Ln();
  114. // Interleaved 2 of 5
  115. $pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
  116. $pdf->write1DBarcode('1234567', 'I25', '', '', '', 18, 0.4, $style, 'N');
  117. $pdf->Ln();
  118. // Interleaved 2 of 5 + CHECKSUM
  119. $pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
  120. $pdf->write1DBarcode('1234567', 'I25+', '', '', '', 18, 0.4, $style, 'N');
  121. // add a page ----------
  122. $pdf->AddPage();
  123. // CODE 128 AUTO
  124. $pdf->Cell(0, 0, 'CODE 128 AUTO', 0, 1);
  125. $pdf->write1DBarcode('CODE 128 AUTO', 'C128', '', '', '', 18, 0.4, $style, 'N');
  126. $pdf->Ln();
  127. // CODE 128 A
  128. $pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
  129. $pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', '', 18, 0.4, $style, 'N');
  130. $pdf->Ln();
  131. // CODE 128 B
  132. $pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
  133. $pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', '', 18, 0.4, $style, 'N');
  134. $pdf->Ln();
  135. // CODE 128 C
  136. $pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
  137. $pdf->write1DBarcode('0123456789', 'C128C', '', '', '', 18, 0.4, $style, 'N');
  138. $pdf->Ln();
  139. // EAN 8
  140. $pdf->Cell(0, 0, 'EAN 8', 0, 1);
  141. $pdf->write1DBarcode('1234567', 'EAN8', '', '', '', 18, 0.4, $style, 'N');
  142. $pdf->Ln();
  143. // EAN 13
  144. $pdf->Cell(0, 0, 'EAN 13', 0, 1);
  145. $pdf->write1DBarcode('1234567890128', 'EAN13', '', '', '', 18, 0.4, $style, 'N');
  146. $pdf->Ln();
  147. // UPC-A
  148. $pdf->Cell(0, 0, 'UPC-A', 0, 1);
  149. $pdf->write1DBarcode('12345678901', 'UPCA', '', '', '', 18, 0.4, $style, 'N');
  150. $pdf->Ln();
  151. // UPC-E
  152. $pdf->Cell(0, 0, 'UPC-E', 0, 1);
  153. $pdf->write1DBarcode('04210000526', 'UPCE', '', '', '', 18, 0.4, $style, 'N');
  154. // add a page ----------
  155. $pdf->AddPage();
  156. // 5-Digits UPC-Based Extention
  157. $pdf->Cell(0, 0, '5-Digits UPC-Based Extention', 0, 1);
  158. $pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
  159. $pdf->Ln();
  160. // 2-Digits UPC-Based Extention
  161. $pdf->Cell(0, 0, '2-Digits UPC-Based Extention', 0, 1);
  162. $pdf->write1DBarcode('34', 'EAN2', '', '', '', 18, 0.4, $style, 'N');
  163. $pdf->Ln();
  164. // MSI
  165. $pdf->Cell(0, 0, 'MSI', 0, 1);
  166. $pdf->write1DBarcode('80523', 'MSI', '', '', '', 18, 0.4, $style, 'N');
  167. $pdf->Ln();
  168. // MSI + CHECKSUM (module 11)
  169. $pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
  170. $pdf->write1DBarcode('80523', 'MSI+', '', '', '', 18, 0.4, $style, 'N');
  171. $pdf->Ln();
  172. // CODABAR
  173. $pdf->Cell(0, 0, 'CODABAR', 0, 1);
  174. $pdf->write1DBarcode('123456789', 'CODABAR', '', '', '', 18, 0.4, $style, 'N');
  175. $pdf->Ln();
  176. // CODE 11
  177. $pdf->Cell(0, 0, 'CODE 11', 0, 1);
  178. $pdf->write1DBarcode('123-456-789', 'CODE11', '', '', '', 18, 0.4, $style, 'N');
  179. $pdf->Ln();
  180. // PHARMACODE
  181. $pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
  182. $pdf->write1DBarcode('789', 'PHARMA', '', '', '', 18, 0.4, $style, 'N');
  183. $pdf->Ln();
  184. // PHARMACODE TWO-TRACKS
  185. $pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
  186. $pdf->write1DBarcode('105', 'PHARMA2T', '', '', '', 18, 2, $style, 'N');
  187. // add a page ----------
  188. $pdf->AddPage();
  189. // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
  190. $pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
  191. $pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', '', 15, 0.6, $style, 'N');
  192. $pdf->Ln();
  193. // POSTNET
  194. $pdf->Cell(0, 0, 'POSTNET', 0, 1);
  195. $pdf->write1DBarcode('98000', 'POSTNET', '', '', '', 15, 0.6, $style, 'N');
  196. $pdf->Ln();
  197. // PLANET
  198. $pdf->Cell(0, 0, 'PLANET', 0, 1);
  199. $pdf->write1DBarcode('98000', 'PLANET', '', '', '', 15, 0.6, $style, 'N');
  200. $pdf->Ln();
  201. // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
  202. $pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
  203. $pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', '', 15, 0.6, $style, 'N');
  204. $pdf->Ln();
  205. // KIX (Klant index - Customer index)
  206. $pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
  207. $pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', '', 15, 0.6, $style, 'N');
  208. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  209. // TEST BARCODE ALIGNMENTS
  210. // add a page
  211. $pdf->AddPage();
  212. // set a background color
  213. $style['bgcolor'] = array(255,255,240);
  214. $style['fgcolor'] = array(127,0,0);
  215. // Left position
  216. $style['position'] = 'L';
  217. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  218. $pdf->Ln(2);
  219. // Center position
  220. $style['position'] = 'C';
  221. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  222. $pdf->Ln(2);
  223. // Right position
  224. $style['position'] = 'R';
  225. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  226. $pdf->Ln(2);
  227. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  228. $style['fgcolor'] = array(0,127,0);
  229. $style['position'] = '';
  230. $style['stretch'] = false; // disable stretch
  231. $style['fitwidth'] = false; // disable fitwidth
  232. // Left alignment
  233. $style['align'] = 'L';
  234. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  235. $pdf->Ln(2);
  236. // Center alignment
  237. $style['align'] = 'C';
  238. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  239. $pdf->Ln(2);
  240. // Right alignment
  241. $style['align'] = 'R';
  242. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  243. $pdf->Ln(2);
  244. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  245. $style['fgcolor'] = array(0,64,127);
  246. $style['position'] = '';
  247. $style['stretch'] = false; // disable stretch
  248. $style['fitwidth'] = true; // disable fitwidth
  249. // Left alignment
  250. $style['cellfitalign'] = 'L';
  251. $pdf->write1DBarcode('LEFT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  252. $pdf->Ln(2);
  253. // Center alignment
  254. $style['cellfitalign'] = 'C';
  255. $pdf->write1DBarcode('CENTER', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  256. $pdf->Ln(2);
  257. // Right alignment
  258. $style['cellfitalign'] = 'R';
  259. $pdf->write1DBarcode('RIGHT', 'C128A', 105, '', 90, 15, 0.4, $style, 'N');
  260. $pdf->Ln(2);
  261. // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  262. $style['fgcolor'] = array(127,0,127);
  263. // Left alignment
  264. $style['position'] = 'L';
  265. $pdf->write1DBarcode('LEFT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  266. $pdf->Ln(2);
  267. // Center alignment
  268. $style['position'] = 'C';
  269. $pdf->write1DBarcode('CENTER', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  270. $pdf->Ln(2);
  271. // Right alignment
  272. $style['position'] = 'R';
  273. $pdf->write1DBarcode('RIGHT', 'C128A', '', '', '', 15, 0.4, $style, 'N');
  274. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  275. // TEST BARCODE STYLE
  276. // define barcode style
  277. $style = array(
  278. 'position' => '',
  279. 'align' => '',
  280. 'stretch' => true,
  281. 'fitwidth' => false,
  282. 'cellfitalign' => '',
  283. 'border' => true,
  284. 'hpadding' => 'auto',
  285. 'vpadding' => 'auto',
  286. 'fgcolor' => array(0,0,128),
  287. 'bgcolor' => array(255,255,128),
  288. 'text' => true,
  289. 'label' => 'CUSTOM LABEL',
  290. 'font' => 'helvetica',
  291. 'fontsize' => 8,
  292. 'stretchtext' => 4
  293. );
  294. // CODE 39 EXTENDED + CHECKSUM
  295. $pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
  296. $pdf->SetLineStyle(array('width' => 1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
  297. $pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 120, 25, 0.4, $style, 'N');
  298. // ---------------------------------------------------------
  299. //Close and output PDF document
  300. $pdf->Output('example_027.pdf', 'I');
  301. //============================================================+
  302. // END OF FILE
  303. //============================================================+