example_050.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. //============================================================+
  3. // File name : example_050.php
  4. // Begin : 2009-04-09
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 050 for TCPDF class
  8. // 2D 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: 2D 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 050');
  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.' 050', 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. // NOTE: 2D barcode algorithms must be implemented on 2dbarcode.php class file.
  59. // set font
  60. $pdf->setFont('helvetica', '', 11);
  61. // add a page
  62. $pdf->AddPage();
  63. // print a message
  64. $txt = "You can also export 2D barcodes in other formats (PNG, SVG, HTML). Check the examples inside the barcode directory.\n";
  65. $pdf->MultiCell(70, 50, $txt, 0, 'J', false, 1, 125, 30, true, 0, false, true, 0, 'T', false);
  66. $pdf->setFont('helvetica', '', 10);
  67. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  68. // set style for barcode
  69. $style = array(
  70. 'border' => true,
  71. 'vpadding' => 'auto',
  72. 'hpadding' => 'auto',
  73. 'fgcolor' => array(0,0,0),
  74. 'bgcolor' => false, //array(255,255,255)
  75. 'module_width' => 1, // width of a single module in points
  76. 'module_height' => 1 // height of a single module in points
  77. );
  78. // write RAW 2D Barcode
  79. $code = '111011101110111,010010001000010,010011001110010,010010000010010,010011101110010';
  80. $pdf->write2DBarcode($code, 'RAW', 80, 30, 30, 20, $style, 'N');
  81. // write RAW2 2D Barcode
  82. $code = '[111011101110111][010010001000010][010011001110010][010010000010010][010011101110010]';
  83. $pdf->write2DBarcode($code, 'RAW2', 80, 60, 30, 20, $style, 'N');
  84. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  85. // set style for barcode
  86. $style = array(
  87. 'border' => 2,
  88. 'vpadding' => 'auto',
  89. 'hpadding' => 'auto',
  90. 'fgcolor' => array(0,0,0),
  91. 'bgcolor' => false, //array(255,255,255)
  92. 'module_width' => 1, // width of a single module in points
  93. 'module_height' => 1 // height of a single module in points
  94. );
  95. // QRCODE,L : QR-CODE Low error correction
  96. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,L', 20, 30, 50, 50, $style, 'N');
  97. $pdf->Text(20, 25, 'QRCODE L');
  98. // QRCODE,M : QR-CODE Medium error correction
  99. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,M', 20, 90, 50, 50, $style, 'N');
  100. $pdf->Text(20, 85, 'QRCODE M');
  101. // QRCODE,Q : QR-CODE Better error correction
  102. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', 20, 150, 50, 50, $style, 'N');
  103. $pdf->Text(20, 145, 'QRCODE Q');
  104. // QRCODE,H : QR-CODE Best error correction
  105. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', 20, 210, 50, 50, $style, 'N');
  106. $pdf->Text(20, 205, 'QRCODE H');
  107. // -------------------------------------------------------------------
  108. // PDF417 (ISO/IEC 15438:2006)
  109. /*
  110. The $type parameter can be simple 'PDF417' or 'PDF417' followed by a
  111. number of comma-separated options:
  112. 'PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6'
  113. Possible options are:
  114. a = aspect ratio (width/height);
  115. e = error correction level (0-8);
  116. Macro Control Block options:
  117. t = total number of macro segments;
  118. s = macro segment index (0-99998);
  119. f = file ID;
  120. o0 = File Name (text);
  121. o1 = Segment Count (numeric);
  122. o2 = Time Stamp (numeric);
  123. o3 = Sender (text);
  124. o4 = Addressee (text);
  125. o5 = File Size (numeric);
  126. o6 = Checksum (numeric).
  127. Parameters t, s and f are required for a Macro Control Block, all other parameters are optional.
  128. To use a comma character ',' on text options, replace it with the character 255: "\xff".
  129. */
  130. $pdf->write2DBarcode('www.tcpdf.org', 'PDF417', 80, 90, 0, 30, $style, 'N');
  131. $pdf->Text(80, 85, 'PDF417 (ISO/IEC 15438:2006)');
  132. // -------------------------------------------------------------------
  133. // DATAMATRIX (ISO/IEC 16022:2006)
  134. $pdf->write2DBarcode('http://www.tcpdf.org', 'DATAMATRIX', 80, 150, 50, 50, $style, 'N');
  135. $pdf->Text(80, 145, 'DATAMATRIX (ISO/IEC 16022:2006)');
  136. // -------------------------------------------------------------------
  137. // new style
  138. $style = array(
  139. 'border' => 2,
  140. 'padding' => 'auto',
  141. 'fgcolor' => array(0,0,255),
  142. 'bgcolor' => array(255,255,64)
  143. );
  144. // QRCODE,H : QR-CODE Best error correction
  145. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', 80, 210, 50, 50, $style, 'N');
  146. $pdf->Text(80, 205, 'QRCODE H - COLORED');
  147. // new style
  148. $style = array(
  149. 'border' => false,
  150. 'padding' => 0,
  151. 'fgcolor' => array(128,0,0),
  152. 'bgcolor' => false
  153. );
  154. // QRCODE,H : QR-CODE Best error correction
  155. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', 140, 210, 50, 50, $style, 'N');
  156. $pdf->Text(140, 205, 'QRCODE H - NO PADDING');
  157. // ---------------------------------------------------------
  158. //Close and output PDF document
  159. $pdf->Output('example_050.pdf', 'I');
  160. //============================================================+
  161. // END OF FILE
  162. //============================================================+