example_012.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. //============================================================+
  3. // File name : example_012.php
  4. // Begin : 2008-03-04
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 012 for TCPDF class
  8. // Graphic Functions
  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 Functions
  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 012');
  35. $pdf->setSubject('TCPDF Tutorial');
  36. $pdf->setKeywords('TCPDF, PDF, example, test, guide');
  37. // disable header and footer
  38. $pdf->setPrintHeader(false);
  39. $pdf->setPrintFooter(false);
  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. // set auto page breaks
  45. $pdf->setAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  46. // set image scale factor
  47. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  48. // set some language-dependent strings (optional)
  49. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  50. require_once(dirname(__FILE__).'/lang/eng.php');
  51. $pdf->setLanguageArray($l);
  52. }
  53. // ---------------------------------------------------------
  54. // set font
  55. $pdf->setFont('helvetica', '', 10);
  56. // add a page
  57. $pdf->AddPage();
  58. $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,20,5,10', 'phase' => 10, 'color' => array(255, 0, 0));
  59. $style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
  60. $style3 = array('width' => 1, 'cap' => 'round', 'join' => 'round', 'dash' => '2,10', 'color' => array(255, 0, 0));
  61. $style4 = array('L' => 0,
  62. 'T' => array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => '20,10', 'phase' => 10, 'color' => array(100, 100, 255)),
  63. 'R' => array('width' => 0.50, 'cap' => 'round', 'join' => 'miter', 'dash' => 0, 'color' => array(50, 50, 127)),
  64. 'B' => array('width' => 0.75, 'cap' => 'square', 'join' => 'miter', 'dash' => '30,10,5,10'));
  65. $style5 = array('width' => 0.25, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 64, 128));
  66. $style6 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => '10,10', 'color' => array(0, 128, 0));
  67. $style7 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 128, 0));
  68. // Line
  69. $pdf->Text(5, 4, 'Line examples');
  70. $pdf->Line(5, 10, 80, 30, $style);
  71. $pdf->Line(5, 10, 5, 30, $style2);
  72. $pdf->Line(5, 10, 80, 10, $style3);
  73. // Rect
  74. $pdf->Text(100, 4, 'Rectangle examples');
  75. $pdf->Rect(100, 10, 40, 20, 'DF', $style4, array(220, 220, 200));
  76. $pdf->Rect(145, 10, 40, 20, 'D', array('all' => $style3));
  77. // Curve
  78. $pdf->Text(5, 34, 'Curve examples');
  79. $pdf->Curve(5, 40, 30, 55, 70, 45, 60, 75, '', $style6);
  80. $pdf->Curve(80, 40, 70, 75, 150, 45, 100, 75, 'F', $style6);
  81. $pdf->Curve(140, 40, 150, 55, 180, 45, 200, 75, 'DF', $style6, array(200, 220, 200));
  82. // Circle and ellipse
  83. $pdf->Text(5, 79, 'Circle and ellipse examples');
  84. $pdf->setLineStyle($style5);
  85. $pdf->Circle(25,105,20);
  86. $pdf->Circle(25,105,10, 90, 180, '', $style6);
  87. $pdf->Circle(25,105,10, 270, 360, 'F');
  88. $pdf->Circle(25,105,10, 270, 360, 'C', $style6);
  89. $pdf->setLineStyle($style5);
  90. $pdf->Ellipse(100,103,40,20);
  91. $pdf->Ellipse(100,105,20,10, 0, 90, 180, '', $style6);
  92. $pdf->Ellipse(100,105,20,10, 0, 270, 360, 'DF', $style6);
  93. $pdf->setLineStyle($style5);
  94. $pdf->Ellipse(175,103,30,15,45);
  95. $pdf->Ellipse(175,105,15,7.50, 45, 90, 180, '', $style6);
  96. $pdf->Ellipse(175,105,15,7.50, 45, 270, 360, 'F', $style6, array(220, 200, 200));
  97. // Polygon
  98. $pdf->Text(5, 129, 'Polygon examples');
  99. $pdf->setLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  100. $pdf->Polygon(array(5,135,45,135,15,165));
  101. $pdf->Polygon(array(60,135,80,135,80,155,70,165,50,155), 'DF', array($style6, $style7, $style7, 0, $style6), array(220, 200, 200));
  102. $pdf->Polygon(array(120,135,140,135,150,155,110,155), 'D', array($style6, 0, $style7, $style6));
  103. $pdf->Polygon(array(160,135,190,155,170,155,200,160,160,165), 'DF', array('all' => $style6), array(220, 220, 220));
  104. // Polygonal Line
  105. $pdf->setLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 164)));
  106. $pdf->PolyLine(array(80,165,90,160,100,165,110,160,120,165,130,160,140,165), 'D', array(), array());
  107. // Regular polygon
  108. $pdf->Text(5, 169, 'Regular polygon examples');
  109. $pdf->setLineStyle($style5);
  110. $pdf->RegularPolygon(20, 190, 15, 6, 0, 1, 'F');
  111. $pdf->RegularPolygon(55, 190, 15, 6);
  112. $pdf->RegularPolygon(55, 190, 10, 6, 45, false, 'DF', array($style6, 0, $style7, 0, $style7, $style7));
  113. $pdf->RegularPolygon(90, 190, 15, 3, 0, true, 'DF', array('all' => $style5), array(200, 220, 200), 'F', array(255, 200, 200));
  114. $pdf->RegularPolygon(125, 190, 15, 4, 30, true, '', array('all' => $style5), array(), '', $style6);
  115. $pdf->RegularPolygon(160, 190, 15, 10);
  116. // Star polygon
  117. $pdf->Text(5, 209, 'Star polygon examples');
  118. $pdf->setLineStyle($style5);
  119. $pdf->StarPolygon(20, 230, 15, 20, 3, 0, 1, 'F');
  120. $pdf->StarPolygon(55, 230, 15, 12, 5);
  121. $pdf->StarPolygon(55, 230, 7, 12, 5, 45, false, 'DF', array('all' => $style7), array(220, 220, 200), 'F', array(255, 200, 200));
  122. $pdf->StarPolygon(90, 230, 15, 20, 6, 0, true, 'DF', array('all' => $style5), array(220, 220, 200), 'F', array(255, 200, 200));
  123. $pdf->StarPolygon(125, 230, 15, 5, 2, 30, true, '', array('all' => $style5), array(), '', $style6);
  124. $pdf->StarPolygon(160, 230, 15, 10, 3);
  125. $pdf->StarPolygon(160, 230, 7, 50, 26);
  126. // Rounded rectangle
  127. $pdf->Text(5, 249, 'Rounded rectangle examples');
  128. $pdf->setLineStyle(array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
  129. $pdf->RoundedRect(5, 255, 40, 30, 3.50, '1111', 'DF');
  130. $pdf->RoundedRect(50, 255, 40, 30, 6.50, '1000');
  131. $pdf->RoundedRect(95, 255, 40, 30, 10.0, '1111', '', $style6);
  132. $pdf->RoundedRect(140, 255, 40, 30, 8.0, '0101', 'DF', $style6, array(200, 200, 200));
  133. // Arrows
  134. $pdf->Text(185, 249, 'Arrows');
  135. $pdf->setLineStyle($style5);
  136. $pdf->setFillColor(255, 0, 0);
  137. $pdf->Arrow(200, 280, 185, 266, 0, 5, 15);
  138. $pdf->Arrow(200, 280, 190, 263, 1, 5, 15);
  139. $pdf->Arrow(200, 280, 195, 261, 2, 5, 15);
  140. $pdf->Arrow(200, 280, 200, 260, 3, 5, 15);
  141. // - . - . - . - . - . - . - . - . - . - . - . - . - . - . -
  142. // ellipse
  143. // add a page
  144. $pdf->AddPage();
  145. $pdf->Cell(0, 0, 'Arc of Ellipse');
  146. // center of ellipse
  147. $xc=100;
  148. $yc=100;
  149. // X Y axis
  150. $pdf->setDrawColor(200, 200, 200);
  151. $pdf->Line($xc-50, $yc, $xc+50, $yc);
  152. $pdf->Line($xc, $yc-50, $xc, $yc+50);
  153. // ellipse axis
  154. $pdf->setDrawColor(200, 220, 255);
  155. $pdf->Line($xc-50, $yc-50, $xc+50, $yc+50);
  156. $pdf->Line($xc-50, $yc+50, $xc+50, $yc-50);
  157. // ellipse
  158. $pdf->setDrawColor(200, 255, 200);
  159. $pdf->Ellipse($xc, $yc, 30, 15, 45, 0, 360, 'D', array(), array(), 2);
  160. // ellipse arc
  161. $pdf->setDrawColor(255, 0, 0);
  162. $pdf->Ellipse($xc, $yc, 30, 15, 45, 45, 90, 'D', array(), array(), 2);
  163. // ---------------------------------------------------------
  164. //Close and output PDF document
  165. $pdf->Output('example_012.pdf', 'I');
  166. //============================================================+
  167. // END OF FILE
  168. //============================================================+