example_030.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. //============================================================+
  3. // File name : example_030.php
  4. // Begin : 2008-06-09
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 030 for TCPDF class
  8. // Colour gradients
  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: Colour gradients
  22. * @author Nicola Asuni
  23. * @since 2008-06-09
  24. * @group color
  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 030');
  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.' 030', 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. // set font
  59. $pdf->setFont('helvetica', 'B', 20);
  60. // --- first page ------------------------------------------
  61. // add a page
  62. $pdf->AddPage();
  63. $pdf->Cell(0, 0, 'TCPDF Gradients', 0, 1, 'C', 0, '', 0, false, 'T', 'M');
  64. // set colors for gradients (r,g,b) or (grey 0-255)
  65. $red = array(255, 0, 0);
  66. $blue = array(0, 0, 200);
  67. $yellow = array(255, 255, 0);
  68. $green = array(0, 255, 0);
  69. $white = array(255);
  70. $black = array(0);
  71. // set the coordinates x1,y1,x2,y2 of the gradient (see linear_gradient_coords.jpg)
  72. $coords = array(0, 0, 1, 0);
  73. // paint a linear gradient
  74. $pdf->LinearGradient(20, 45, 80, 80, $red, $blue, $coords);
  75. // write label
  76. $pdf->Text(20, 130, 'LinearGradient()');
  77. // set the coordinates fx,fy,cx,cy,r of the gradient (see radial_gradient_coords.jpg)
  78. $coords = array(0.5, 0.5, 1, 1, 1.2);
  79. // paint a radial gradient
  80. $pdf->RadialGradient(110, 45, 80, 80, $white, $black, $coords);
  81. // write label
  82. $pdf->Text(110, 130, 'RadialGradient()');
  83. // paint a coons patch mesh with default coordinates
  84. $pdf->CoonsPatchMesh(20, 155, 80, 80, $yellow, $blue, $green, $red);
  85. // write label
  86. $pdf->Text(20, 240, 'CoonsPatchMesh()');
  87. // set the coordinates for the cubic Bézier points x1,y1 ... x12, y12 of the patch (see coons_patch_mesh_coords.jpg)
  88. $coords = array(
  89. 0.00,0.00, 0.33,0.20, //lower left
  90. 0.67,0.00, 1.00,0.00, 0.80,0.33, //lower right
  91. 0.80,0.67, 1.00,1.00, 0.67,0.80, //upper right
  92. 0.33,1.00, 0.00,1.00, 0.20,0.67, //upper left
  93. 0.00,0.33); //lower left
  94. $coords_min = 0; //minimum value of the coordinates
  95. $coords_max = 1; //maximum value of the coordinates
  96. // paint a coons patch gradient with the above coordinates
  97. $pdf->CoonsPatchMesh(110, 155, 80, 80, $yellow, $blue, $green, $red, $coords, $coords_min, $coords_max);
  98. // write label
  99. $pdf->Text(110, 240, 'CoonsPatchMesh()');
  100. // --- second page -----------------------------------------
  101. $pdf->AddPage();
  102. // first patch: f = 0
  103. $patch_array[0]['f'] = 0;
  104. $patch_array[0]['points'] = array(
  105. 0.00,0.00, 0.33,0.00,
  106. 0.67,0.00, 1.00,0.00, 1.00,0.33,
  107. 0.8,0.67, 1.00,1.00, 0.67,0.8,
  108. 0.33,1.80, 0.00,1.00, 0.00,0.67,
  109. 0.00,0.33);
  110. $patch_array[0]['colors'][0] = array('r' => 255, 'g' => 255, 'b' => 0);
  111. $patch_array[0]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
  112. $patch_array[0]['colors'][2] = array('r' => 0, 'g' => 255,'b' => 0);
  113. $patch_array[0]['colors'][3] = array('r' => 255, 'g' => 0,'b' => 0);
  114. // second patch - above the other: f = 2
  115. $patch_array[1]['f'] = 2;
  116. $patch_array[1]['points'] = array(
  117. 0.00,1.33,
  118. 0.00,1.67, 0.00,2.00, 0.33,2.00,
  119. 0.67,2.00, 1.00,2.00, 1.00,1.67,
  120. 1.5,1.33);
  121. $patch_array[1]['colors'][0]=array('r' => 0, 'g' => 0, 'b' => 0);
  122. $patch_array[1]['colors'][1]=array('r' => 255, 'g' => 0, 'b' => 255);
  123. // third patch - right of the above: f = 3
  124. $patch_array[2]['f'] = 3;
  125. $patch_array[2]['points'] = array(
  126. 1.33,0.80,
  127. 1.67,1.50, 2.00,1.00, 2.00,1.33,
  128. 2.00,1.67, 2.00,2.00, 1.67,2.00,
  129. 1.33,2.00);
  130. $patch_array[2]['colors'][0] = array('r' => 0, 'g' => 255, 'b' => 255);
  131. $patch_array[2]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 0);
  132. // fourth patch - below the above, which means left(?) of the above: f = 1
  133. $patch_array[3]['f'] = 1;
  134. $patch_array[3]['points'] = array(
  135. 2.00,0.67,
  136. 2.00,0.33, 2.00,0.00, 1.67,0.00,
  137. 1.33,0.00, 1.00,0.00, 1.00,0.33,
  138. 0.8,0.67);
  139. $patch_array[3]['colors'][0] = array('r' => 0, 'g' => 0, 'b' => 0);
  140. $patch_array[3]['colors'][1] = array('r' => 0, 'g' => 0, 'b' => 255);
  141. $coords_min = 0;
  142. $coords_max = 2;
  143. $pdf->CoonsPatchMesh(10, 45, 190, 200, '', '', '', '', $patch_array, $coords_min, $coords_max);
  144. // write label
  145. $pdf->Text(10, 250, 'CoonsPatchMesh()');
  146. // ---------------------------------------------------------
  147. //Close and output PDF document
  148. $pdf->Output('example_030.pdf', 'D');
  149. //============================================================+
  150. // END OF FILE
  151. //============================================================+