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.

210 lines
6.3 KiB

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