example_013.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. //============================================================+
  3. // File name : example_013.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2010-08-08
  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 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: Graphic Transformations
  25. * @author Nicola Asuni
  26. * @since 2008-03-04
  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 013');
  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.' 013', 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. // 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. //============================================================+