example_057.php 8.7 KB

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