example_050.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. //============================================================+
  3. // File name : example_050.php
  4. // Begin : 2009-04-09
  5. // Last Update : 2011-09-22
  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', '', 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 source code documentation of TCPDF2DBarcode class for further information.";
  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. //============================================================+