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.

188 lines
5.8 KiB

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