You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
8.5 KiB

  1. <?php
  2. //============================================================+
  3. // File name : example_048.php
  4. // Begin : 2009-03-20
  5. // Last Update : 2013-05-14
  6. //
  7. // Description : Example 048 for TCPDF class
  8. // HTML tables and table headers
  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: HTML tables and table headers
  22. * @author Nicola Asuni
  23. * @since 2009-03-20
  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 048');
  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.' 048', 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 HTML tables', '', 0, 'L', true, 0, false, false, 0);
  61. $pdf->SetFont('helvetica', '', 8);
  62. // -----------------------------------------------------------------------------
  63. $tbl = <<<EOD
  64. <table cellspacing="0" cellpadding="1" border="1">
  65. <tr>
  66. <td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3</td>
  67. <td>COL 2 - ROW 1</td>
  68. <td>COL 3 - ROW 1</td>
  69. </tr>
  70. <tr>
  71. <td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
  72. <td>COL 3 - ROW 2</td>
  73. </tr>
  74. <tr>
  75. <td>COL 3 - ROW 3</td>
  76. </tr>
  77. </table>
  78. EOD;
  79. $pdf->writeHTML($tbl, true, false, false, false, '');
  80. // -----------------------------------------------------------------------------
  81. $tbl = <<<EOD
  82. <table cellspacing="0" cellpadding="1" border="1">
  83. <tr>
  84. <td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3<br />text line<br />text line<br />text line<br />text line<br />text line<br />text line</td>
  85. <td>COL 2 - ROW 1</td>
  86. <td>COL 3 - ROW 1</td>
  87. </tr>
  88. <tr>
  89. <td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
  90. <td>COL 3 - ROW 2</td>
  91. </tr>
  92. <tr>
  93. <td>COL 3 - ROW 3</td>
  94. </tr>
  95. </table>
  96. EOD;
  97. $pdf->writeHTML($tbl, true, false, false, false, '');
  98. // -----------------------------------------------------------------------------
  99. $tbl = <<<EOD
  100. <table cellspacing="0" cellpadding="1" border="1">
  101. <tr>
  102. <td rowspan="3">COL 1 - ROW 1<br />COLSPAN 3<br />text line<br />text line<br />text line<br />text line<br />text line<br />text line</td>
  103. <td>COL 2 - ROW 1</td>
  104. <td>COL 3 - ROW 1</td>
  105. </tr>
  106. <tr>
  107. <td rowspan="2">COL 2 - ROW 2 - COLSPAN 2<br />text line<br />text line<br />text line<br />text line</td>
  108. <td>COL 3 - ROW 2<br />text line<br />text line</td>
  109. </tr>
  110. <tr>
  111. <td>COL 3 - ROW 3</td>
  112. </tr>
  113. </table>
  114. EOD;
  115. $pdf->writeHTML($tbl, true, false, false, false, '');
  116. // -----------------------------------------------------------------------------
  117. $tbl = <<<EOD
  118. <table border="1">
  119. <tr>
  120. <th rowspan="3">Left column</th>
  121. <th colspan="5">Heading Column Span 5</th>
  122. <th colspan="9">Heading Column Span 9</th>
  123. </tr>
  124. <tr>
  125. <th rowspan="2">Rowspan 2<br />This is some text that fills the table cell.</th>
  126. <th colspan="2">span 2</th>
  127. <th colspan="2">span 2</th>
  128. <th rowspan="2">2 rows</th>
  129. <th colspan="8">Colspan 8</th>
  130. </tr>
  131. <tr>
  132. <th>1a</th>
  133. <th>2a</th>
  134. <th>1b</th>
  135. <th>2b</th>
  136. <th>1</th>
  137. <th>2</th>
  138. <th>3</th>
  139. <th>4</th>
  140. <th>5</th>
  141. <th>6</th>
  142. <th>7</th>
  143. <th>8</th>
  144. </tr>
  145. </table>
  146. EOD;
  147. $pdf->writeHTML($tbl, true, false, false, false, '');
  148. // -----------------------------------------------------------------------------
  149. // Table with rowspans and THEAD
  150. $tbl = <<<EOD
  151. <table border="1" cellpadding="2" cellspacing="2">
  152. <thead>
  153. <tr style="background-color:#FFFF00;color:#0000FF;">
  154. <td width="30" align="center"><b>A</b></td>
  155. <td width="140" align="center"><b>XXXX</b></td>
  156. <td width="140" align="center"><b>XXXX</b></td>
  157. <td width="80" align="center"> <b>XXXX</b></td>
  158. <td width="80" align="center"><b>XXXX</b></td>
  159. <td width="45" align="center"><b>XXXX</b></td>
  160. </tr>
  161. <tr style="background-color:#FF0000;color:#FFFF00;">
  162. <td width="30" align="center"><b>B</b></td>
  163. <td width="140" align="center"><b>XXXX</b></td>
  164. <td width="140" align="center"><b>XXXX</b></td>
  165. <td width="80" align="center"> <b>XXXX</b></td>
  166. <td width="80" align="center"><b>XXXX</b></td>
  167. <td width="45" align="center"><b>XXXX</b></td>
  168. </tr>
  169. </thead>
  170. <tr>
  171. <td width="30" align="center">1.</td>
  172. <td width="140" rowspan="6">XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
  173. <td width="140">XXXX<br />XXXX</td>
  174. <td width="80">XXXX<br />XXXX</td>
  175. <td width="80">XXXX</td>
  176. <td align="center" width="45">XXXX<br />XXXX</td>
  177. </tr>
  178. <tr>
  179. <td width="30" align="center" rowspan="3">2.</td>
  180. <td width="140" rowspan="3">XXXX<br />XXXX</td>
  181. <td width="80">XXXX<br />XXXX</td>
  182. <td width="80">XXXX<br />XXXX</td>
  183. <td align="center" width="45">XXXX<br />XXXX</td>
  184. </tr>
  185. <tr>
  186. <td width="80">XXXX<br />XXXX<br />XXXX<br />XXXX</td>
  187. <td width="80">XXXX<br />XXXX</td>
  188. <td align="center" width="45">XXXX<br />XXXX</td>
  189. </tr>
  190. <tr>
  191. <td width="80" rowspan="2" >RRRRRR<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX<br />XXXX</td>
  192. <td width="80">XXXX<br />XXXX</td>
  193. <td align="center" width="45">XXXX<br />XXXX</td>
  194. </tr>
  195. <tr>
  196. <td width="30" align="center">3.</td>
  197. <td width="140">XXXX1<br />XXXX</td>
  198. <td width="80">XXXX<br />XXXX</td>
  199. <td align="center" width="45">XXXX<br />XXXX</td>
  200. </tr>
  201. <tr>
  202. <td width="30" align="center">4.</td>
  203. <td width="140">XXXX<br />XXXX</td>
  204. <td width="80">XXXX<br />XXXX</td>
  205. <td width="80">XXXX<br />XXXX</td>
  206. <td align="center" width="45">XXXX<br />XXXX</td>
  207. </tr>
  208. </table>
  209. EOD;
  210. $pdf->writeHTML($tbl, true, false, false, false, '');
  211. $pdf->writeHTML($tbl, true, false, false, false, '');
  212. // -----------------------------------------------------------------------------
  213. // NON-BREAKING TABLE (nobr="true")
  214. $tbl = <<<EOD
  215. <table border="1" cellpadding="2" cellspacing="2" nobr="true">
  216. <tr>
  217. <th colspan="3" align="center">NON-BREAKING TABLE</th>
  218. </tr>
  219. <tr>
  220. <td>1-1</td>
  221. <td>1-2</td>
  222. <td>1-3</td>
  223. </tr>
  224. <tr>
  225. <td>2-1</td>
  226. <td>3-2</td>
  227. <td>3-3</td>
  228. </tr>
  229. <tr>
  230. <td>3-1</td>
  231. <td>3-2</td>
  232. <td>3-3</td>
  233. </tr>
  234. </table>
  235. EOD;
  236. $pdf->writeHTML($tbl, true, false, false, false, '');
  237. // -----------------------------------------------------------------------------
  238. // NON-BREAKING ROWS (nobr="true")
  239. $tbl = <<<EOD
  240. <table border="1" cellpadding="2" cellspacing="2" align="center">
  241. <tr nobr="true">
  242. <th colspan="3">NON-BREAKING ROWS</th>
  243. </tr>
  244. <tr nobr="true">
  245. <td>ROW 1<br />COLUMN 1</td>
  246. <td>ROW 1<br />COLUMN 2</td>
  247. <td>ROW 1<br />COLUMN 3</td>
  248. </tr>
  249. <tr nobr="true">
  250. <td>ROW 2<br />COLUMN 1</td>
  251. <td>ROW 2<br />COLUMN 2</td>
  252. <td>ROW 2<br />COLUMN 3</td>
  253. </tr>
  254. <tr nobr="true">
  255. <td>ROW 3<br />COLUMN 1</td>
  256. <td>ROW 3<br />COLUMN 2</td>
  257. <td>ROW 3<br />COLUMN 3</td>
  258. </tr>
  259. </table>
  260. EOD;
  261. $pdf->writeHTML($tbl, true, false, false, false, '');
  262. // -----------------------------------------------------------------------------
  263. //Close and output PDF document
  264. $pdf->Output('example_048.pdf', 'I');
  265. //============================================================+
  266. // END OF FILE
  267. //============================================================+