example_013.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. //============================================================+
  3. // File name : example_013.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 013 for TCPDF class
  8. // Graphic Transformations
  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: Graphic Transformations
  22. * @author Nicola Asuni
  23. * @since 2008-03-04
  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 013');
  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.' 013', 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. // add a page
  59. $pdf->AddPage();
  60. $pdf->Write(0, 'Graphic Transformations', '', 0, 'C', 1, 0, false, false, 0);
  61. // set font
  62. $pdf->SetFont('helvetica', '', 10);
  63. // --- Scaling ---------------------------------------------
  64. $pdf->SetDrawColor(200);
  65. $pdf->SetTextColor(200);
  66. $pdf->Rect(50, 70, 40, 10, 'D');
  67. $pdf->Text(50, 66, 'Scale');
  68. $pdf->SetDrawColor(0);
  69. $pdf->SetTextColor(0);
  70. // Start Transformation
  71. $pdf->StartTransform();
  72. // Scale by 150% centered by (50,80) which is the lower left corner of the rectangle
  73. $pdf->ScaleXY(150, 50, 80);
  74. $pdf->Rect(50, 70, 40, 10, 'D');
  75. $pdf->Text(50, 66, 'Scale');
  76. // Stop Transformation
  77. $pdf->StopTransform();
  78. // --- Translation -----------------------------------------
  79. $pdf->SetDrawColor(200);
  80. $pdf->SetTextColor(200);
  81. $pdf->Rect(125, 70, 40, 10, 'D');
  82. $pdf->Text(125, 66, 'Translate');
  83. $pdf->SetDrawColor(0);
  84. $pdf->SetTextColor(0);
  85. // Start Transformation
  86. $pdf->StartTransform();
  87. // Translate 7 to the right, 5 to the bottom
  88. $pdf->Translate(7, 5);
  89. $pdf->Rect(125, 70, 40, 10, 'D');
  90. $pdf->Text(125, 66, 'Translate');
  91. // Stop Transformation
  92. $pdf->StopTransform();
  93. // --- Rotation --------------------------------------------
  94. $pdf->SetDrawColor(200);
  95. $pdf->SetTextColor(200);
  96. $pdf->Rect(70, 100, 40, 10, 'D');
  97. $pdf->Text(70, 96, 'Rotate');
  98. $pdf->SetDrawColor(0);
  99. $pdf->SetTextColor(0);
  100. // Start Transformation
  101. $pdf->StartTransform();
  102. // Rotate 20 degrees counter-clockwise centered by (70,110) which is the lower left corner of the rectangle
  103. $pdf->Rotate(20, 70, 110);
  104. $pdf->Rect(70, 100, 40, 10, 'D');
  105. $pdf->Text(70, 96, 'Rotate');
  106. // Stop Transformation
  107. $pdf->StopTransform();
  108. // --- Skewing ---------------------------------------------
  109. $pdf->SetDrawColor(200);
  110. $pdf->SetTextColor(200);
  111. $pdf->Rect(125, 100, 40, 10, 'D');
  112. $pdf->Text(125, 96, 'Skew');
  113. $pdf->SetDrawColor(0);
  114. $pdf->SetTextColor(0);
  115. // Start Transformation
  116. $pdf->StartTransform();
  117. // skew 30 degrees along the x-axis centered by (125,110) which is the lower left corner of the rectangle
  118. $pdf->SkewX(30, 125, 110);
  119. $pdf->Rect(125, 100, 40, 10, 'D');
  120. $pdf->Text(125, 96, 'Skew');
  121. // Stop Transformation
  122. $pdf->StopTransform();
  123. // --- Mirroring horizontally ------------------------------
  124. $pdf->SetDrawColor(200);
  125. $pdf->SetTextColor(200);
  126. $pdf->Rect(70, 130, 40, 10, 'D');
  127. $pdf->Text(70, 126, 'MirrorH');
  128. $pdf->SetDrawColor(0);
  129. $pdf->SetTextColor(0);
  130. // Start Transformation
  131. $pdf->StartTransform();
  132. // mirror horizontally with axis of reflection at x-position 70 (left side of the rectangle)
  133. $pdf->MirrorH(70);
  134. $pdf->Rect(70, 130, 40, 10, 'D');
  135. $pdf->Text(70, 126, 'MirrorH');
  136. // Stop Transformation
  137. $pdf->StopTransform();
  138. // --- Mirroring vertically --------------------------------
  139. $pdf->SetDrawColor(200);
  140. $pdf->SetTextColor(200);
  141. $pdf->Rect(125, 130, 40, 10, 'D');
  142. $pdf->Text(125, 126, 'MirrorV');
  143. $pdf->SetDrawColor(0);
  144. $pdf->SetTextColor(0);
  145. // Start Transformation
  146. $pdf->StartTransform();
  147. // mirror vertically with axis of reflection at y-position 140 (bottom side of the rectangle)
  148. $pdf->MirrorV(140);
  149. $pdf->Rect(125, 130, 40, 10, 'D');
  150. $pdf->Text(125, 126, 'MirrorV');
  151. // Stop Transformation
  152. $pdf->StopTransform();
  153. // --- Point reflection ------------------------------------
  154. $pdf->SetDrawColor(200);
  155. $pdf->SetTextColor(200);
  156. $pdf->Rect(70, 160, 40, 10, 'D');
  157. $pdf->Text(70, 156, 'MirrorP');
  158. $pdf->SetDrawColor(0);
  159. $pdf->SetTextColor(0);
  160. // Start Transformation
  161. $pdf->StartTransform();
  162. // point reflection at the lower left point of rectangle
  163. $pdf->MirrorP(70,170);
  164. $pdf->Rect(70, 160, 40, 10, 'D');
  165. $pdf->Text(70, 156, 'MirrorP');
  166. // Stop Transformation
  167. $pdf->StopTransform();
  168. // --- Mirroring against a straigth line described by a point (120, 120) and an angle -20°
  169. $angle=-20;
  170. $px=120;
  171. $py=170;
  172. // just for visualisation: the straight line to mirror against
  173. $pdf->SetDrawColor(200);
  174. $pdf->Line($px-1,$py-1,$px+1,$py+1);
  175. $pdf->Line($px-1,$py+1,$px+1,$py-1);
  176. $pdf->StartTransform();
  177. $pdf->Rotate($angle, $px, $py);
  178. $pdf->Line($px-5, $py, $px+60, $py);
  179. $pdf->StopTransform();
  180. $pdf->SetDrawColor(200);
  181. $pdf->SetTextColor(200);
  182. $pdf->Rect(125, 160, 40, 10, 'D');
  183. $pdf->Text(125, 156, 'MirrorL');
  184. $pdf->SetDrawColor(0);
  185. $pdf->SetTextColor(0);
  186. //Start Transformation
  187. $pdf->StartTransform();
  188. //mirror against the straight line
  189. $pdf->MirrorL($angle, $px, $py);
  190. $pdf->Rect(125, 160, 40, 10, 'D');
  191. $pdf->Text(125, 156, 'MirrorL');
  192. //Stop Transformation
  193. $pdf->StopTransform();
  194. // ---------------------------------------------------------
  195. //Close and output PDF document
  196. $pdf->Output('example_013.pdf', 'I');
  197. //============================================================+
  198. // END OF FILE
  199. //============================================================+