example_057.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. //============================================================+
  3. // File name : example_057.php
  4. // Begin : 2010-04-03
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 057 for TCPDF class
  8. // Cell vertical alignments
  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: Cell vertical alignments
  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 057');
  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.' 057', 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, 'Example of alignment options for Cell()', '', 0, 'L', true, 0, false, false, 0);
  61. $pdf->SetFont('helvetica', '', 11);
  62. // set border width
  63. $pdf->SetLineWidth(0.7);
  64. // set color for cell border
  65. $pdf->SetDrawColor(0,128,255);
  66. $pdf->setCellHeightRatio(3);
  67. $pdf->SetXY(15, 60);
  68. // text on center
  69. $pdf->Cell(30, 0, 'Top-Center', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'C');
  70. $pdf->Cell(30, 0, 'Center-Center', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'C');
  71. $pdf->Cell(30, 0, 'Bottom-Center', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'C');
  72. $pdf->Cell(30, 0, 'Ascent-Center', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'C');
  73. $pdf->Cell(30, 0, 'Baseline-Center', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'C');
  74. $pdf->Cell(30, 0, 'Descent-Center', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'C');
  75. $pdf->SetXY(15, 90);
  76. // text on top
  77. $pdf->Cell(30, 0, 'Top-Top', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'T');
  78. $pdf->Cell(30, 0, 'Center-Top', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'T');
  79. $pdf->Cell(30, 0, 'Bottom-Top', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'T');
  80. $pdf->Cell(30, 0, 'Ascent-Top', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'T');
  81. $pdf->Cell(30, 0, 'Baseline-Top', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'T');
  82. $pdf->Cell(30, 0, 'Descent-Top', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'T');
  83. $pdf->SetXY(15, 120);
  84. // text on bottom
  85. $pdf->Cell(30, 0, 'Top-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'T', 'B');
  86. $pdf->Cell(30, 0, 'Center-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'C', 'B');
  87. $pdf->Cell(30, 0, 'Bottom-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'B', 'B');
  88. $pdf->Cell(30, 0, 'Ascent-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'A', 'B');
  89. $pdf->Cell(30, 0, 'Baseline-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'L', 'B');
  90. $pdf->Cell(30, 0, 'Descent-Bottom', 1, $ln=0, 'C', 0, '', 0, false, 'D', 'B');
  91. // draw some reference lines
  92. $linestyle = array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => '', 'phase' => 0, 'color' => array(255, 0, 0));
  93. $pdf->Line(15, 60, 195, 60, $linestyle);
  94. $pdf->Line(15, 90, 195, 90, $linestyle);
  95. $pdf->Line(15, 120, 195, 120, $linestyle);
  96. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  97. // Print an image to explain cell measures
  98. $pdf->Image('images/tcpdf_cell.png', 15, 160, 100, 100, 'PNG', '', '', false, 300, '', false, false, 0, false, false, false);
  99. $legend = 'LEGEND:
  100. X: cell x top-left origin (top-right for RTL)
  101. Y: cell y top-left origin (top-right for RTL)
  102. CW: cell width
  103. CH: cell height
  104. LW: line width
  105. NRL: normal line position
  106. EXT: external line position
  107. INT: internal line position
  108. ML: margin left
  109. MR: margin right
  110. MT: margin top
  111. MB: margin bottom
  112. PL: padding left
  113. PR: padding right
  114. PT: padding top
  115. PB: padding bottom
  116. TW: text width
  117. FA: font ascent
  118. FB: font baseline
  119. FD: font descent';
  120. $pdf->SetFont('helvetica', '', 10);
  121. $pdf->setCellHeightRatio(1.25);
  122. $pdf->MultiCell(0, 0, $legend, 0, 'L', false, 1, 125, 160, true, 0, false, true, 0, 'T', false);
  123. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  124. // CELL BORDERS
  125. // add a page
  126. $pdf->AddPage();
  127. $pdf->SetFont('helvetica', 'B', 20);
  128. $pdf->Write(0, 'Example of borders for Cell()', '', 0, 'L', true, 0, false, false, 0);
  129. $pdf->SetFont('helvetica', '', 11);
  130. // set border width
  131. $pdf->SetLineWidth(0.508);
  132. // set color for cell border
  133. $pdf->SetDrawColor(0,128,255);
  134. // set filling color
  135. $pdf->SetFillColor(255,255,128);
  136. // set cell height ratio
  137. $pdf->setCellHeightRatio(3);
  138. $pdf->Cell(30, 0, '1', 1, 1, 'C', 1, '', 0, false, 'T', 'C');
  139. $pdf->Ln(2);
  140. $pdf->Cell(30, 0, 'LTRB', 'LTRB', 1, 'C', 1, '', 0, false, 'T', 'C');
  141. $pdf->Ln(2);
  142. $pdf->Cell(30, 0, 'LTR', 'LTR', 1, 'C', 1, '', 0, false, 'T', 'C');
  143. $pdf->Ln(2);
  144. $pdf->Cell(30, 0, 'TRB', 'TRB', 1, 'C', 1, '', 0, false, 'T', 'C');
  145. $pdf->Ln(2);
  146. $pdf->Cell(30, 0, 'LRB', 'LRB', 1, 'C', 1, '', 0, false, 'T', 'C');
  147. $pdf->Ln(2);
  148. $pdf->Cell(30, 0, 'LTB', 'LTB', 1, 'C', 1, '', 0, false, 'T', 'C');
  149. $pdf->Ln(2);
  150. $pdf->Cell(30, 0, 'LT', 'LT', 1, 'C', 1, '', 0, false, 'T', 'C');
  151. $pdf->Ln(2);
  152. $pdf->Cell(30, 0, 'TR', 'TR', 1, 'C', 1, '', 0, false, 'T', 'C');
  153. $pdf->Ln(2);
  154. $pdf->Cell(30, 0, 'RB', 'RB', 1, 'C', 1, '', 0, false, 'T', 'C');
  155. $pdf->Ln(2);
  156. $pdf->Cell(30, 0, 'LB', 'LB', 1, 'C', 1, '', 0, false, 'T', 'C');
  157. $pdf->Ln(2);
  158. $pdf->Cell(30, 0, 'LR', 'LR', 1, 'C', 1, '', 0, false, 'T', 'C');
  159. $pdf->Ln(2);
  160. $pdf->Cell(30, 0, 'TB', 'TB', 1, 'C', 1, '', 0, false, 'T', 'C');
  161. $pdf->Ln(2);
  162. $pdf->Cell(30, 0, 'L', 'L', 1, 'C', 1, '', 0, false, 'T', 'C');
  163. $pdf->Ln(2);
  164. $pdf->Cell(30, 0, 'T', 'T', 1, 'C', 1, '', 0, false, 'T', 'C');
  165. $pdf->Ln(2);
  166. $pdf->Cell(30, 0, 'R', 'R', 1, 'C', 1, '', 0, false, 'T', 'C');
  167. $pdf->Ln(2);
  168. $pdf->Cell(30, 0, 'B', 'B', 1, 'C', 1, '', 0, false, 'T', 'C');
  169. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  170. // ADVANCED SETTINGS FOR CELL BORDERS
  171. // add a page
  172. $pdf->AddPage();
  173. $pdf->SetFont('helvetica', 'B', 20);
  174. $pdf->Write(0, 'Example of advanced border settings for Cell()', '', 0, 'L', true, 0, false, false, 0);
  175. $pdf->SetFont('helvetica', '', 11);
  176. // set border width
  177. $pdf->SetLineWidth(1);
  178. // set color for cell border
  179. $pdf->SetDrawColor(0,128,255);
  180. // set filling color
  181. $pdf->SetFillColor(255,255,128);
  182. $border = array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
  183. $pdf->Cell(30, 0, 'LTRB', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
  184. $pdf->Ln(5);
  185. $border = array(
  186. 'L' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)),
  187. 'R' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 255)),
  188. 'T' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 255, 0)),
  189. 'B' => array('width' => 2, 'cap' => 'square', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 255)));
  190. $pdf->Cell(30, 0, 'LTRB', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
  191. $pdf->Ln(5);
  192. $border = array('mode' => 'ext', 'LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
  193. $pdf->Cell(30, 0, 'LTRB EXT', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
  194. $pdf->Ln(5);
  195. $border = array('mode' => 'int', 'LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0)));
  196. $pdf->Cell(30, 0, 'LTRB INT', $border, 1, 'C', 1, '', 0, false, 'T', 'C');
  197. $pdf->Ln(5);
  198. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  199. // reset pointer to the last page
  200. $pdf->lastPage();
  201. // ---------------------------------------------------------
  202. //Close and output PDF document
  203. $pdf->Output('example_057.pdf', 'I');
  204. //============================================================+
  205. // END OF FILE
  206. //============================================================+