fpdf_table.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /****************************************************************************
  3. * Software: FPDF class extention *
  4. * Creates Pdf Tables *
  5. * Version: 2.0 *
  6. * Date: 2005/07/20 *
  7. * Author: Bintintan Andrei -- klodoma@ar-sd.net *
  8. * *
  9. * License: Freeware *
  10. * *
  11. * You may use and modify this software as you wish. *
  12. ****************************************************************************/
  13. require_once('fpdf.php');
  14. //extension class
  15. class FPDF_TABLE extends FPDF
  16. {
  17. var $tb_columns; //number of columns of the table
  18. var $tb_header_type; //array which contains the header characteristics and texts
  19. var $tb_header_draw; //TRUE or FALSE, the header is drawed or not
  20. var $tb_border_draw; //TRUE or FALSE, the table border is drawed or not
  21. var $tb_data_type; //array which contains the data characteristics (only the characteristics)
  22. var $tb_table_type; //array which contains the table charactersitics
  23. var $table_startx, $table_starty; //the X and Y position where the table starts
  24. var $Draw_Header_Command; //command which determines in the DrawData first the header draw
  25. var $New_Page_Commit; // = true/false if a new page has been comited
  26. var $Data_On_Current_Page; // = true/false ... if on current page was some data written
  27. //returns the width of the page in user units
  28. function PageWidth(){
  29. return (int) $this->w-$this->rMargin-$this->lMargin;
  30. }
  31. //constructor(not a real one, but have to call it first)
  32. //we initialize all the variables that we use
  33. function Table_Init($col_no = 0, $header_draw = true, $border_draw = true){
  34. $this->tb_columns = $col_no;
  35. $this->tb_header_type = Array();
  36. $this->tb_header_draw = $header_draw;
  37. $this->tb_border_draw = $border_draw;
  38. $this->tb_data_type = Array();
  39. $this->tb_type = Array();
  40. $this->table_startx = $this->GetX();
  41. $this->table_starty = $this->GetY();
  42. $this->Draw_Header_Command = false; //by default we don't draw the header
  43. $this->New_Page_Commit = false; //NO we do not consider first time a new page
  44. $this->Data_On_Current_Page = false;
  45. }
  46. //Sets the number of columns of the table
  47. function Set_Table_Columns($nr){
  48. $this->tb_columns = $nr;
  49. }
  50. /*
  51. Characteristics constants for Header Type:
  52. EVERY CELL FROM THE TABLE IS A MULTICELL
  53. WIDTH - this is the cell width. This value must be sent only to the HEADER!!!!!!!!
  54. T_COLOR - text color = array(r,g,b);
  55. T_SIZE - text size
  56. T_FONT - text font - font type = "Arial", "Times"
  57. T_ALIGN - text align - "RLCJ"
  58. V_ALIGN - text vertical alignment - "TMB"
  59. T_TYPE - text type (Bold Italic etc)
  60. LN_SPACE - space between lines
  61. BG_COLOR - background color = array(r,g,b);
  62. BRD_COLOR - border color = array(r,g,b);
  63. BRD_SIZE - border size --
  64. BRD_TYPE - border size -- up down, with border without!!! etc
  65. BRD_TYPE_NEW_PAGE - border type on new page - this is user only if specified(<>'')
  66. TEXT - header text -- THIS ALSO BELONGS ONLY TO THE HEADER!!!!
  67. all these setting conform to the settings from the multicell functions!!!!
  68. */
  69. /*
  70. Function: Set_Header_Type($type_arr) -- sets the array for the header type
  71. type array =
  72. array(
  73. 0=>array(
  74. "WIDTH" => 10,
  75. "T_COLOR" => array(120,120,120),
  76. "T_SIZE" => 5,
  77. ...
  78. "TEXT" => "Header text 1"
  79. ),
  80. 1=>array(
  81. ...
  82. ),
  83. );
  84. where 0,1... are the column number
  85. */
  86. function Set_Header_Type($type_arr){
  87. $this->tb_header_type = $type_arr;
  88. }
  89. /*
  90. Characteristics constants for Data Type:
  91. EVERY CELL FROM THE TABLE IS A MULTICELL
  92. T_COLOR - text color = array(r,g,b);
  93. T_SIZE - text size
  94. T_FONT - text font - font type = "Arial", "Times"
  95. T_ALIGN - text align - "RLCJ"
  96. V_ALIGN - text vertical alignment - "TMB"
  97. T_TYPE - text type (Bold Italic etc)
  98. LN_SPACE - space between lines
  99. BG_COLOR - background color = array(r,g,b);
  100. BRD_COLOR - border color = array(r,g,b);
  101. BRD_SIZE - border size --
  102. BRD_TYPE - border size -- up down, with border without!!! etc
  103. BRD_TYPE_NEW_PAGE - border type on new page - this is user only if specified(<>'')
  104. all these settings conform to the settings from the multicell functions!!!!
  105. */
  106. /*
  107. Function: Set_data_Type($type_arr) -- sets the array for the header type
  108. type array =
  109. array(
  110. 0=>array(
  111. "T_COLOR" => array(120,120,120),
  112. "T_SIZE" => 5,
  113. ...
  114. "BRD_TYPE" => 1
  115. ),
  116. 1=>array(
  117. ...
  118. ),
  119. );
  120. where 0,1... are the column number
  121. */
  122. function Set_Data_Type($type_arr){
  123. $this->tb_data_type = $type_arr;
  124. }
  125. /*
  126. Function Set_Table_Type
  127. $type_arr = array(
  128. "BRD_COLOR"=> array (120,120,120), //border color
  129. "BRD_SIZE"=>5), //border line width
  130. "TB_COLUMNS"=>5), //the number of columns
  131. "TB_ALIGN"=>"L"), //the align of the table, possible values = L, R, C equivalent to Left, Right, Center
  132. 'L_MARGIN' => 0// left margin... reference from this->lmargin values
  133. )
  134. */
  135. function Set_Table_Type($type_arr){
  136. if (isset($type_arr['TB_COLUMNS'])) $this->tb_columns = $type_arr['TB_COLUMNS'];
  137. if (!isset($type_arr['L_MARGIN'])) $type_arr['L_MARGIN']=0;//default values
  138. $this->tb_table_type = $type_arr;
  139. }
  140. //this functiondraws the exterior table border!!!!
  141. function Draw_Table_Border(){
  142. /* "BRD_COLOR"=> array (120,120,120), //border color
  143. "BRD_SIZE"=>5), //border line width
  144. "TB_COLUMNS"=>5), //the number of columns
  145. "TB_ALIGN"=>"L"), //the align of the table, possible values = L, R, C equivalent to Left, Right, Center
  146. */
  147. if ( ! $this->tb_border_draw ) return;
  148. if ( ! $this->Data_On_Current_Page) return; //there was no data on the current page
  149. //set the colors
  150. list($r, $g, $b) = $this->tb_table_type['BRD_COLOR'];
  151. $this->SetDrawColor($r, $g, $b);
  152. //set the line width
  153. $this->SetLineWidth($this->tb_table_type['BRD_SIZE']);
  154. //draw the border
  155. $this->Rect(
  156. $this->table_startx,
  157. $this->table_starty,
  158. $this->Get_Table_Width(),
  159. $this->GetY()-$this->table_starty);
  160. }
  161. function End_Page_Border(){
  162. if (isset($this->tb_table_type['BRD_TYPE_END_PAGE'])){
  163. if (strpos($this->tb_table_type['BRD_TYPE_END_PAGE'], 'B') >= 0){
  164. //set the colors
  165. list($r, $g, $b) = $this->tb_table_type['BRD_COLOR'];
  166. $this->SetDrawColor($r, $g, $b);
  167. //set the line width
  168. $this->SetLineWidth($this->tb_table_type['BRD_SIZE']);
  169. //draw the line
  170. $this->Line($this->table_startx, $this->GetY(), $this->table_startx + $this->Get_Table_Width(), $this->GetY());
  171. }
  172. }
  173. }
  174. //returns the table width in user units
  175. function Get_Table_Width()
  176. {
  177. //calculate the table width
  178. $tb_width = 0;
  179. for ($i=0; $i < $this->tb_columns; $i++){
  180. $tb_width += $this->tb_header_type[$i]['WIDTH'];
  181. }
  182. return $tb_width;
  183. }
  184. //alignes the table to C, L or R(default is L)
  185. function Table_Align(){
  186. //check if the table is aligned
  187. if (isset($this->tb_table_type['TB_ALIGN'])) $tb_align = $this->tb_table_type['TB_ALIGN']; else $tb_align='';
  188. //set the table align
  189. switch($tb_align){
  190. case 'C':
  191. $this->SetX($this->lMargin + $this->tb_table_type['L_MARGIN'] + ($this->PageWidth() - $this->Get_Table_Width())/2);
  192. break;
  193. case 'R':
  194. $this->SetX($this->lMargin + $this->tb_table_type['L_MARGIN'] + ($this->PageWidth() - $this->Get_Table_Width()));
  195. break;
  196. default:
  197. $this->SetX($this->lMargin + $this->tb_table_type['L_MARGIN']);
  198. break;
  199. }//if (isset($this->tb_table_type['TB_ALIGN'])){
  200. }
  201. //Draws the Header
  202. function Draw_Header(){
  203. $this->Draw_Header_Command = true;
  204. }
  205. //Draws the Header
  206. function Draw_Header_( $next_line_height = 0 ){
  207. $this->Table_Align();
  208. $this->table_startx = $this->GetX();
  209. $this->table_starty = $this->GetY();
  210. //if the header will be showed
  211. if ( ! $this->tb_header_draw ) return;
  212. $h = 0;
  213. $xx = Array();
  214. //calculate the maximum height of the cells
  215. for($i=0;$i<$this->tb_columns;$i++)
  216. {
  217. $this->SetFont( $this->tb_header_type[$i]['T_FONT'],
  218. $this->tb_header_type[$i]['T_TYPE'],
  219. $this->tb_header_type[$i]['T_SIZE']);
  220. $this->tb_header_type[$i]['CELL_WIDTH'] = $this->tb_header_type[$i]['WIDTH'];
  221. if (isset($this->tb_header_type[$i]['COLSPAN'])){
  222. $colspan = (int) $this->tb_header_type[$i]['COLSPAN'];//convert to integer
  223. for ($j = 1; $j < $colspan; $j++){
  224. //if there is a colspan, then calculate the number of lines also with the with of the next cell
  225. if (($i + $j) < $this->tb_columns)
  226. $this->tb_header_type[$i]['CELL_WIDTH'] += $this->tb_header_type[$i + $j]['WIDTH'];
  227. }
  228. }
  229. $this->tb_header_type[$i]['CELL_LINES'] =
  230. $this->NbLines($this->tb_header_type[$i]['CELL_WIDTH'],$this->tb_header_type[$i]['TEXT']);
  231. //this is the maximum cell height
  232. $h = max($h, $this->tb_header_type[$i]['LN_SIZE'] * $this->tb_header_type[$i]['CELL_LINES']);
  233. if (isset($data[$i]['COLSPAN'])){
  234. //just skip the other cells
  235. $i = $i + $colspan - 1;
  236. }
  237. }
  238. //Issue a page break first if needed
  239. //calculate the header hight and the next data line hight
  240. $this->CheckPageBreak($h + $next_line_height, false);
  241. //Draw the cells of the row
  242. for($i=0; $i<$this->tb_columns; $i++)
  243. {
  244. //border size BRD_SIZE
  245. $this->SetLineWidth($this->tb_header_type[$i]['BRD_SIZE']);
  246. //fill color = BG_COLOR
  247. list($r, $g, $b) = $this->tb_header_type[$i]['BG_COLOR'];
  248. $this->SetFillColor($r, $g, $b);
  249. //Draw Color = BRD_COLOR
  250. list($r, $g, $b) = $this->tb_header_type[$i]['BRD_COLOR'];
  251. $this->SetDrawColor($r, $g, $b);
  252. //Text Color = T_COLOR
  253. list($r, $g, $b) = $this->tb_header_type[$i]['T_COLOR'];
  254. $this->SetTextColor($r, $g, $b);
  255. //Set the font, font type and size
  256. $this->SetFont( $this->tb_header_type[$i]['T_FONT'],
  257. $this->tb_header_type[$i]['T_TYPE'],
  258. $this->tb_header_type[$i]['T_SIZE']);
  259. //Save the current position
  260. $x=$this->GetX();
  261. $y=$this->GetY();
  262. if ($this->New_Page_Commit){
  263. if (isset($this->tb_header_type[$i]['BRD_TYPE_NEW_PAGE'])){
  264. $this->tb_header_type[$i]['BRD_TYPE'] .= $this->tb_header_type[$i]['BRD_TYPE_NEW_PAGE'];
  265. }
  266. }
  267. //Print the text
  268. $this->MultiCellTable(
  269. $this->tb_header_type[$i]['CELL_WIDTH'],
  270. $this->tb_header_type[$i]['LN_SIZE'],
  271. $this->tb_header_type[$i]['TEXT'],
  272. $this->tb_header_type[$i]['BRD_TYPE'],
  273. $this->tb_header_type[$i]['T_ALIGN'],
  274. $this->tb_header_type[$i]['V_ALIGN'],
  275. 1,
  276. $h - $this->tb_header_type[$i]['LN_SIZE'] * $this->tb_header_type[$i]['CELL_LINES']
  277. );
  278. //Put the position to the right of the cell
  279. $this->SetXY($x+$this->tb_header_type[$i]['CELL_WIDTH'],$y);
  280. if (isset($this->tb_header_type[$i]['COLSPAN'])){
  281. $i = $i + (int)$this->tb_header_type[$i]['COLSPAN'] - 1;
  282. }
  283. }
  284. //Go to the next line
  285. $this->Ln($h);
  286. $this->Draw_Header_Command = false;
  287. $this->New_Page_Commit = false;
  288. $this->Data_On_Current_Page = true;
  289. }
  290. //this function Draws the data's from the table
  291. //have to call this function after the table initialization, after the table, header and data types are set
  292. //and after the header is drawed
  293. /*
  294. $header = true -> on new page draws the header
  295. = false - > the header is not drawed
  296. */
  297. function Draw_Data($data, $header = true){
  298. $h = 0;
  299. $xx = Array();
  300. $tt = Array();
  301. //calculate the maximum height of the cells
  302. for($i=0; $i < $this->tb_columns; $i++)
  303. {
  304. if (!isset($data[$i]['T_FONT'])) $data[$i]['T_FONT'] = $this->tb_data_type[$i]['T_FONT'];
  305. if (!isset($data[$i]['T_TYPE'])) $data[$i]['T_TYPE'] = $this->tb_data_type[$i]['T_TYPE'];
  306. if (!isset($data[$i]['T_SIZE'])) $data[$i]['T_SIZE'] = $this->tb_data_type[$i]['T_SIZE'];
  307. if (!isset($data[$i]['T_COLOR'])) $data[$i]['T_COLOR'] = $this->tb_data_type[$i]['T_COLOR'];
  308. if (!isset($data[$i]['T_ALIGN'])) $data[$i]['T_ALIGN'] = $this->tb_data_type[$i]['T_ALIGN'];
  309. if (!isset($data[$i]['V_ALIGN'])) $data[$i]['V_ALIGN'] = $this->tb_data_type[$i]['V_ALIGN'];
  310. if (!isset($data[$i]['LN_SIZE'])) $data[$i]['LN_SIZE'] = $this->tb_data_type[$i]['LN_SIZE'];
  311. if (!isset($data[$i]['BRD_SIZE'])) $data[$i]['BRD_SIZE'] = $this->tb_data_type[$i]['BRD_SIZE'];
  312. if (!isset($data[$i]['BRD_COLOR'])) $data[$i]['BRD_COLOR'] = $this->tb_data_type[$i]['BRD_COLOR'];
  313. if (!isset($data[$i]['BRD_TYPE'])) $data[$i]['BRD_TYPE'] = $this->tb_data_type[$i]['BRD_TYPE'];
  314. if (!isset($data[$i]['BG_COLOR'])) $data[$i]['BG_COLOR'] = $this->tb_data_type[$i]['BG_COLOR'];
  315. $this->SetFont( $data[$i]['T_FONT'],
  316. $data[$i]['T_TYPE'],
  317. $data[$i]['T_SIZE']);
  318. $data[$i]['CELL_WIDTH'] = $this->tb_header_type[$i]['WIDTH'];
  319. if (isset($data[$i]['COLSPAN'])){
  320. $colspan = (int) $data[$i]['COLSPAN'];//convert to integer
  321. for ($j = 1; $j < $colspan; $j++){
  322. //if there is a colspan, then calculate the number of lines also with the with of the next cell
  323. if (($i + $j) < $this->tb_columns)
  324. $data[$i]['CELL_WIDTH'] += $this->tb_header_type[$i + $j]['WIDTH'];
  325. }
  326. }
  327. $data[$i]['CELL_LINES'] = $this->NbLines($data[$i]['CELL_WIDTH'], $data[$i]['TEXT']);
  328. //this is the maximum cell height
  329. $h = max($h, $data[$i]['LN_SIZE'] * $data[$i]['CELL_LINES']);
  330. if (isset($data[$i]['COLSPAN'])){
  331. //just skip the other cells
  332. $i = $i + $colspan - 1;
  333. }
  334. }
  335. $this->CheckPageBreak($h, $header);
  336. if ($this->Draw_Header_Command){//draw the header
  337. $this->Draw_Header_($h);
  338. }
  339. $this->Table_Align();
  340. //Draw the cells of the row
  341. for($i=0;$i<$this->tb_columns;$i++)
  342. {
  343. //border size BRD_SIZE
  344. $this->SetLineWidth($data[$i]['BRD_SIZE']);
  345. //fill color = BG_COLOR
  346. list($r, $g, $b) = $data[$i]['BG_COLOR'];
  347. $this->SetFillColor($r, $g, $b);
  348. //Draw Color = BRD_COLOR
  349. list($r, $g, $b) = $data[$i]['BRD_COLOR'];
  350. $this->SetDrawColor($r, $g, $b);
  351. //Text Color = T_COLOR
  352. list($r, $g, $b) = $data[$i]['T_COLOR'];
  353. $this->SetTextColor($r, $g, $b);
  354. //Set the font, font type and size
  355. $this->SetFont( $data[$i]['T_FONT'],
  356. $data[$i]['T_TYPE'],
  357. $data[$i]['T_SIZE']);
  358. //Save the current position
  359. $x=$this->GetX();
  360. $y=$this->GetY();
  361. //print the text
  362. $this->MultiCellTable(
  363. $data[$i]['CELL_WIDTH'],
  364. $data[$i]['LN_SIZE'],
  365. $data[$i]['TEXT'],
  366. $data[$i]['BRD_TYPE'],
  367. $data[$i]['T_ALIGN'],
  368. $data[$i]['V_ALIGN'],
  369. 1,
  370. $h - $data[$i]['LN_SIZE'] * $data[$i]['CELL_LINES']
  371. );
  372. //Put the position to the right of the cell
  373. $this->SetXY($x + $data[$i]['CELL_WIDTH'],$y);
  374. //if we have colspan, just ignore the next cells
  375. if (isset($data[$i]['COLSPAN'])){
  376. $i = $i + (int)$data[$i]['COLSPAN'] - 1;
  377. }
  378. }
  379. $this->Data_On_Current_Page = true;
  380. //Go to the next line
  381. $this->Ln($h);
  382. }
  383. //if the table is bigger than a page then it jumps to next page and draws the header
  384. /*
  385. $h = is the height that if is overriden than the document jumps to a new page
  386. $header = true/false = this specifies at a new page we write again the header or not. This variable
  387. is used at the moment when the header draw makes the new page jump
  388. */
  389. function CheckPageBreak($h, $header = true)
  390. {
  391. //If the height h would cause an overflow, add a new page immediately
  392. if($this->GetY()+$h > $this->PageBreakTrigger){
  393. $this->Draw_Table_Border();//draw the table border
  394. $this->End_Page_Border();//if there is a special handling for end page??? this is specific for me
  395. $this->AddPage($this->CurOrientation);//add a new page
  396. $this->Data_On_Current_Page = false;
  397. $this->New_Page_Commit = true;//new page commit
  398. $this->table_startx = $this->GetX();
  399. $this->table_starty = $this->GetY();
  400. if ($header) $this ->Draw_Header();//if we have to draw the header!!!
  401. }
  402. //align the table
  403. $this->Table_Align();
  404. }
  405. /** This method returns the number of lines that will a text ocupy on the specified width
  406. Call:
  407. @param
  408. $w - width
  409. $txt - text
  410. @return number
  411. */
  412. function NbLines($w,$txt)
  413. {
  414. //Computes the number of lines a MultiCell of width w will take
  415. $cw=&$this->CurrentFont['cw'];
  416. if($w==0)
  417. $w=$this->w-$this->rMargin-$this->x;
  418. $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
  419. $s=str_replace("\r",'',$txt);
  420. $nb=strlen($s);
  421. if($nb>0 and $s[$nb-1]=="\n")
  422. $nb--;
  423. $sep=-1;
  424. $i=0;
  425. $j=0;
  426. $l=0;
  427. $nl=1;
  428. while($i<$nb)
  429. {
  430. $c=$s[$i];
  431. if($c=="\n")
  432. {
  433. $i++;
  434. $sep=-1;
  435. $j=$i;
  436. $l=0;
  437. $nl++;
  438. continue;
  439. }
  440. if($c==' ')
  441. $sep=$i;
  442. $l+=$cw[$c];
  443. if($l>$wmax)
  444. {
  445. if($sep==-1)
  446. {
  447. if($i==$j)
  448. $i++;
  449. }
  450. else
  451. $i=$sep+1;
  452. $sep=-1;
  453. $j=$i;
  454. $l=0;
  455. $nl++;
  456. }
  457. else
  458. $i++;
  459. }
  460. return $nl;
  461. }
  462. /** This method allows printing text with line breaks.
  463. It works like a modified MultiCell
  464. Call:
  465. @param
  466. $w - width
  467. $h - line height
  468. $txt - the outputed text
  469. $border - border(LRTB 0 or 1)
  470. $align - horizontal align 'JLR'
  471. $fill - fill (1/0)
  472. $vh - vertical adjustment - the Multicell Height will be with this VH Higher!!!!
  473. $valign - Vertical Alignment - Top, Middle, Bottom
  474. @return nothing
  475. */
  476. function MultiCellTable($w, $h, $txt, $border=0, $align='J', $valign='T', $fill=0, $vh=0)
  477. {
  478. $b1 = '';//border for top cell
  479. $b2 = '';//border for middle cell
  480. $b3 = '';//border for bottom cell
  481. if($border)
  482. {
  483. if($border==1)
  484. {
  485. $border = 'LTRB';
  486. $b1 = 'LRT';//without the bottom
  487. $b2 = 'LR';//without the top and bottom
  488. $b3 = 'LRB';//without the top
  489. }
  490. else
  491. {
  492. $b2='';
  493. if(is_int(strpos($border,'L')))
  494. $b2.='L';
  495. if(is_int(strpos($border,'R')))
  496. $b2.='R';
  497. $b1=is_int(strpos($border,'T')) ? $b2.'T' : $b2;
  498. $b3=is_int(strpos($border,'B')) ? $b2.'B' : $b2;
  499. }
  500. }
  501. switch ($valign){
  502. case 'T':
  503. $wh_T = 0;//Top width
  504. $wh_B = $vh - $wh_T;//Bottom width
  505. break;
  506. case 'M':
  507. $wh_T = $vh/2;
  508. $wh_B = $vh/2;
  509. break;
  510. case 'B':
  511. $wh_T = $vh;
  512. $wh_B = 0;
  513. break;
  514. default://default is TOP ALIGN
  515. $wh_T = 0;//Top width
  516. $wh_B = $vh - $wh_T;//Bottom width
  517. }
  518. //save the X position
  519. $x = $this->x;
  520. /*
  521. if $wh_T == 0 that means that we have no vertical adjustments so I will skip the cells that
  522. draws the top and bottom borders
  523. */
  524. if ($wh_T != 0)//only when there is a difference
  525. {
  526. //draw the top borders!!!
  527. $this->Cell($w,$wh_T,'',$b1,2,$align,$fill);
  528. }
  529. $b2 = is_int(strpos($border,'T')) && ($wh_T == 0) ? $b2.'T' : $b2;
  530. $b2 = is_int(strpos($border,'B')) && ($wh_B == 0) ? $b2.'B' : $b2;
  531. $this->MultiCell($w,$h,$txt,$b2,$align,$fill);
  532. if ($wh_B != 0){//only when there is a difference
  533. //go to the saved X position
  534. //a multicell always runs to the begin of line
  535. $this->x = $x;
  536. $this->Cell($w, $wh_B, '', $b3, 2, $align,$fill);
  537. $this->x=$this->lMargin;
  538. }
  539. }
  540. }//end of pdf_table class
  541. ?>