example_013.php 6.7 KB

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