example_030.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. //============================================================+
  3. // File name : example_030.php
  4. // Begin : 2008-06-09
  5. // Last Update : 2010-08-08
  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 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: Colour gradients
  25. * @author Nicola Asuni
  26. * @since 2008-06-09
  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 030');
  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.' 030', 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. // 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', 'I');
  147. //============================================================+
  148. // END OF FILE
  149. //============================================================+