example_050.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. //============================================================+
  3. // File name : example_050.php
  4. // Begin : 2009-04-09
  5. // Last Update : 2010-08-08
  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 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: 2D 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 050');
  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.' 050', 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. // NOTE: 2D barcode algorithms must be implemented on 2dbarcode.php class file.
  57. // set font
  58. $pdf->SetFont('helvetica', '', 10);
  59. // add a page
  60. $pdf->AddPage();
  61. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  62. // set style for barcode
  63. $style = array(
  64. 'border' => true,
  65. 'vpadding' => 'auto',
  66. 'hpadding' => 'auto',
  67. 'fgcolor' => array(0,0,0),
  68. 'bgcolor' => false, //array(255,255,255)
  69. 'module_width' => 1, // width of a single module in points
  70. 'module_height' => 1 // height of a single module in points
  71. );
  72. // write RAW 2D Barcode
  73. $pdf->SetXY(30, 30);
  74. $code = '111011101110111,010010001000010,010011001110010,010010000010010,010011101110010';
  75. $pdf->write2DBarcode($code, 'RAW', '', '', 30, 20, $style, 'N');
  76. $pdf->SetXY(100, 30);
  77. // write RAW2 2D Barcode
  78. $code = '[111011101110111][010010001000010][010011001110010][010010000010010][010011101110010]';
  79. $pdf->write2DBarcode($code, 'RAW2', '', '', 30, 20, $style, 'N');
  80. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  81. // set style for barcode
  82. $style = array(
  83. 'border' => 2,
  84. 'vpadding' => 'auto',
  85. 'hpadding' => 'auto',
  86. 'fgcolor' => array(0,0,0),
  87. 'bgcolor' => false, //array(255,255,255)
  88. 'module_width' => 1, // width of a single module in points
  89. 'module_height' => 1 // height of a single module in points
  90. );
  91. // QRCODE,L : QR-CODE Low error correction
  92. $pdf->SetXY(30, 60);
  93. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,L', '', '', 50, 50, $style, 'N');
  94. $pdf->Text(30, 55, 'QRCODE L');
  95. // QRCODE,M : QR-CODE Medium error correction
  96. $pdf->SetXY(100, 60);
  97. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,M', '', '', 50, 50, $style, 'N');
  98. $pdf->Text(100, 55, 'QRCODE M');
  99. // QRCODE,Q : QR-CODE Better error correction
  100. $pdf->SetXY(30, 120);
  101. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,Q', '', '', 50, 50, $style, 'N');
  102. $pdf->Text(30, 115, 'QRCODE Q');
  103. // QRCODE,H : QR-CODE Best error correction
  104. $pdf->SetXY(100, 120);
  105. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', '', '', 50, 50, $style, 'N');
  106. $pdf->Text(100, 115, '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 parametrs are optional.
  128. To use a comma character ',' on text options, replace it with the character 255: "\xff".
  129. */
  130. $pdf->SetXY(30, 180);
  131. $pdf->write2DBarcode('www.tcpdf.org', 'PDF417', '', '', 0, 30, $style, 'N');
  132. $pdf->Text(30, 175, 'PDF417 (ISO/IEC 15438:2006)');
  133. // -------------------------------------------------------------------
  134. // new style
  135. $style = array(
  136. 'border' => 2,
  137. 'padding' => 'auto',
  138. 'fgcolor' => array(0,0,255),
  139. 'bgcolor' => array(255,255,64)
  140. );
  141. // QRCODE,H : QR-CODE Best error correction
  142. $pdf->SetXY(30, 220);
  143. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', '', '', 50, 50, $style, 'N');
  144. $pdf->Text(30, 215, '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->SetXY(100, 220);
  154. $pdf->write2DBarcode('www.tcpdf.org', 'QRCODE,H', '', '', 50, 50, $style, 'N');
  155. $pdf->Text(100, 215, 'QRCODE H - NO PADDING');
  156. // ---------------------------------------------------------
  157. //Close and output PDF document
  158. $pdf->Output('example_050.pdf', 'I');
  159. //============================================================+
  160. // END OF FILE
  161. //============================================================+