example_057.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. //============================================================+
  3. // File name : example_057.php
  4. // Begin : 2010-04-03
  5. // Last Update : 2010-10-05
  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 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: Cell vertical alignments
  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 057');
  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.' 057', 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, '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. //============================================================+