You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
11 KiB

4 years ago
  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. */
  25. // Include the main TCPDF library (search for installation path).
  26. require_once('tcpdf_include.php');
  27. // create new PDF document
  28. $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  29. // set document information
  30. $pdf->SetCreator(PDF_CREATOR);
  31. $pdf->SetAuthor('Nicola Asuni');
  32. $pdf->SetTitle('TCPDF Example 027');
  33. $pdf->SetSubject('TCPDF Tutorial');
  34. $pdf->SetKeywords('TCPDF, PDF, example, test, guide');
  35. // set default header data
  36. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 027', PDF_HEADER_STRING);
  37. // set header and footer fonts
  38. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  39. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  40. // set default monospaced font
  41. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  42. // set margins
  43. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  44. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  45. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  46. // set auto page breaks
  47. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  48. // set image scale factor
  49. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  50. // set some language-dependent strings (optional)
  51. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  52. require_once(dirname(__FILE__).'/lang/eng.php');
  53. $pdf->setLanguageArray($l);
  54. }
  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 examples inside the barcodes directory.\n";
  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 Extension
  157. $pdf->Cell(0, 0, '5-Digits UPC-Based Extension', 0, 1);
  158. $pdf->write1DBarcode('51234', 'EAN5', '', '', '', 18, 0.4, $style, 'N');
  159. $pdf->Ln();
  160. // 2-Digits UPC-Based Extension
  161. $pdf->Cell(0, 0, '2-Digits UPC-Based Extension', 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. //============================================================+