Question : FPDF PDF Generator Support

I needs help with coding FPDF PDF Generator. Not sure if I'm asking the question in the correct zone as I could find a dedicated zone.

http://www.fpdf.org/

I need to do the following

- check where you are -> GetY() and see how much space is available
- calculate the height of next table - that´s up to you
- check if table fits into free space
- add a new page if table does not fit.

See my code attached. I will explain further in my next post.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
//============================================================+
// File name   : example_011.php
// Begin       : 2008-03-04
// Last Update : 2009-09-30
// 
// Description : Example 011 for TCPDF class
//               Colored Table
// 
// Author: Nicola Asuni
// 
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com s.r.l.
//               Via Della Pace, 11
//               09044 Quartucciu (CA)
//               ITALY
//               www.tecnick.com
//               [email protected]
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Colored Table
 * @author Nicola Asuni
 * @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - [email protected]
 * @link http://tcpdf.org
 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 * @since 2008-03-04
 */

require_once('../../tcpdf/config/lang/eng.php');
require_once('../../tcpdf/tcpdf.php');

// extend TCPF with custom functions

class MYPDF extends TCPDF {
	
	// Load table data from file
	public function LoadData($file) {
		// Read file lines
		$lines = file($file);
		$data = array();
		foreach($lines as $line) {
			$data[] = explode(';', chop($line));
		}
		return $data;
	}
		
	// Colored table
	public function ColoredTable($header,$data) {
		// Colors, line width and bold font
		$this->SetFillColor(81, 98, 126);
		$this->SetTextColor(255);
		$this->SetDrawColor(153, 153, 153);
		$this->SetLineWidth(0.25);
		$this->SetFont('helvetica', 'B', 9);
		/** Header
		$w = array(80, 40, 30, 30);
		for($i = 0; $i < count($header); $i++)
		$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
		$this->Ln();
		*/
		// Header
		$w = array(41, 33, 30, 43, 35);
		for($i = 0; $i < count($header); $i++)
		
		foreach($header as $header_row) {
			$this->Cell($w[0], 7, $header_row[0], 1, 0, 'L', 1);
			$this->Cell($w[1], 7, $header_row[1], 1, 0, 'L', 1);
			$this->Cell($w[2], 7, $header_row[2], 1, 0, 'L', 1);
			$this->Cell($w[3], 7, $header_row[3], 1, 0, 'L', 1);
			$this->Cell($w[4], 7, $header_row[4], 1, 0, 'R', 1);
			$this->Ln();
		}
		// Color and font restoration
		$this->SetFillColor(224, 235, 255);
		$this->SetTextColor(0);
		$this->SetFont('');
		// Data
		$fill = 0;
		foreach($data as $row) {
			$this->Cell($w[0], 6, $row[0], 'LR', 0, 'L', $fill);
			$this->Cell($w[1], 6, $row[1].'mm', 'LR', 0, 'L', $fill);
			$this->Cell($w[2], 6, $row[2].'m', 'LR', 0, 'L', $fill);
			$this->Cell($w[3], 6, $row[3], 'LR', 0, 'L', $fill);
			$this->Cell($w[4], 6, $row[4], 'LR', 0, 'R', $fill);
			$this->Ln();
			$fill=!$fill;
		}
		$this->Cell(array_sum($w), 0, '', 'T');
	}
}

	/** header title */
	define ('PDF_HEADER_TITLE2', 'Media Price List');

	/** header description string */
	define ('PDF_HEADER_STRING2', "Call 01628 560892\nwww.selectechdirect.co.uk");

	/** image logo 2 */
	define ('PDF_HEADER_LOGO2', 'Selectech_Logo.jpg');

	/** header logo image width [mm] 2 */
	define ('PDF_HEADER_LOGO_WIDTH2', 65);

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Selectech');
$pdf->SetTitle('Selectech Price List');
$pdf->SetSubject('Media Price List');
$pdf->SetKeywords('Selectech, PDF, Media, Price List');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO2, PDF_HEADER_LOGO_WIDTH2, PDF_HEADER_TITLE2, PDF_HEADER_STRING2);


// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); 

//set some language-dependent strings
$pdf->setLanguageArray($l); 

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();

// create some HTML content
$pdf->writeHTML('<h1>' .$row_rs_customer_selected['customer_name']. ' - Media Price List<br/></h1>', true, 0, true, 0);

$Num2 = 1;

mysql_select_db($database_conn_selectech, $conn_selectech);
$query_rs_media_category_list = "SELECT * FROM media_category";
$rs_media_category_list = mysql_query($query_rs_media_category_list, $conn_selectech) or die(mysql_error());
$row_rs_media_category_list = mysql_fetch_assoc($rs_media_category_list);
$totalRows_rs_media_category_list = mysql_num_rows($rs_media_category_list);

do {

mysql_select_db($database_conn_selectech, $conn_selectech);
$query_rs_media_group = "SELECT * FROM media_group WHERE media_category_id = " . $row_rs_media_category_list['id'];
$rs_media_group = mysql_query($query_rs_media_group, $conn_selectech) or die(mysql_error());
$row_rs_media_group = mysql_fetch_assoc($rs_media_group);
$totalRows_rs_media_group = mysql_num_rows($rs_media_group);


$pdf->writeHTML('<div style="color:#424856; font-size: 14pt; font-weight: bold;">' .$row_rs_media_category_list['category_name']. '</div>', true, 0, true, 0);


do {
	
mysql_select_db($database_conn_selectech, $conn_selectech);
$query_rs_media = "SELECT me.*, mg.selectech_group_code, mpo.*
				   FROM media me
				   JOIN media_group mg
				   ON me.media_group_id = mg.id
				   LEFT JOIN media_price_override mpo
				   ON me.id = mpo.media_roll_id AND mpo.customer_id = ". $CustomerCookieValue. "
				   WHERE me.media_group_id = " . $row_rs_media_group['id'] . "
				   ORDER BY me.width ASC";
$rs_media = mysql_query($query_rs_media, $conn_selectech) or die(mysql_error());
$row_rs_media = mysql_fetch_assoc($rs_media);
$totalRows_rs_media = mysql_num_rows($rs_media);

mysql_select_db($database_conn_selectech, $conn_selectech);
$query_rs_media_group_override = "SELECT * FROM media_group_override WHERE customer_id = ".$CustomerCookieValue." AND media_group_id = ".$row_rs_media_group['id'];
$rs_media_group_override = mysql_query($query_rs_media_group_override, $conn_selectech) or die(mysql_error());
$row_rs_media_group_override = mysql_fetch_assoc($rs_media_group_override);
$totalRows_rs_media_group_override = mysql_num_rows($rs_media_group_override);

mysql_select_db($database_conn_selectech, $conn_selectech);
$query_rs_media_brand = "SELECT * FROM media_brand WHERE id = " . $row_rs_media_group['brand_id'];
$rs_media_brand = mysql_query($query_rs_media_brand, $conn_selectech) or die(mysql_error());
$row_rs_media_brand = mysql_fetch_assoc($rs_media_brand);
$totalRows_rs_media_brand = mysql_num_rows($rs_media_brand);


$pdf->writeHTML('<div style="color:#000000; font-size: 10pt; font-weight: bold;"><br/>' .$row_rs_media_brand['brand'] . ' ' . $row_rs_media_group['name']. '<br/></div>', true, 0, true, 0);

//Column titles
$header=array();
$header[] = array('Code', 'Width', 'Length', 'Weight / Thickness', 'Price');

//Data loading
$data=array();
do  {
	
	  $mark_up_adjusted = $row_rs_mark_up_selected['mark_up_rate'] - 100;
	  
	  if ($mark_up_adjusted < 0) { $mark_up_adjusted_revised = -$mark_up_adjusted; } else  {  $mark_up_adjusted_revised = $mark_up_adjusted; }
	  
	  if (is_null($row_rs_media['single_price_override'])) {  
	  $single_price_adjusted = $row_rs_media['single_price'] / ($mark_up_adjusted_revised / 100);
	  } else {
	  $single_price_adjusted = $row_rs_media['single_price_override']  ;
	  }
	  
	  if ($row_rs_customer_selected['id'] == 1) {
	  
	  $single_price_converted = $row_rs_media['single_price'] * $row_rs_exchange_rate_selected['rate'];
	  } else { 
	  
	  $single_price_converted = $single_price_adjusted * $row_rs_exchange_rate_selected['rate'];
	  }
	  
	  if (is_null($row_rs_media['ten_price_override'])) {  
	  $ten_price_adjusted = $row_rs_media['10_price'] / ($mark_up_adjusted_revised / 100);
	  } else {
	  $ten_price_adjusted = $row_rs_media['ten_price_override'];
	  }
	  
	  if ($row_rs_customer_selected['id'] == 1) {
	  $ten_price_converted = $row_rs_media['10_price'] * $row_rs_exchange_rate_selected['rate'];
	  } else { 
	  $ten_price_converted = $ten_price_adjusted * $row_rs_exchange_rate_selected['rate'];
	  }
	  
	  if (is_null($row_rs_media['pallet_price_override'])) {  
	  $pallet_price_adjusted = $row_rs_media['pallet_price'] / ($mark_up_adjusted_revised / 100);
	  } else {
	  $pallet_price_adjusted = $row_rs_media['pallet_price_override'];
	  }
	  
	  if ($row_rs_customer_selected['id'] == 1) {
	  $pallet_price_converted = $row_rs_media['pallet_price'] * $row_rs_exchange_rate_selected['rate'];
	  } else { 
	  $pallet_price_converted = $pallet_price_adjusted * $row_rs_exchange_rate_selected['rate'];
	  }

if(empty($row_rs_media['weight'])) { 
	$weight = ""; 
	} else { 
	$weight = $row_rs_media['weight']. "gsm";
	}
if(empty($row_rs_media['thickness'])) { 
	$thickness = "";
	} else { 
	$thickness = $row_rs_media['thickness']. "mic";
	}
	

$data[] = array(
	$row_rs_media['selectech_group_code'] . "-" . $row_rs_media['width'] . "-" . $row_rs_media['length'],
	$row_rs_media['width'],
	$row_rs_media['length'],
	$weight. $thickness,
	utf8_encode($row_rs_exchange_rate_selected['symbol']). number_format(round($single_price_converted, 2), 2)
   );
 
}  while ($row_rs_media  = mysql_fetch_assoc($rs_media));

// print colored table

$pdf->ColoredTable($header, $data);

// ---------------------------------------------------------

if (is_null($row_rs_media_group_override['notes_override'])) {
	  $notes = $row_rs_media_group['notes'];
	  } else {
	  $notes = $row_rs_media_group_override['notes_override'];
	  }

if (!is_null($notes)) {
	
	$pdf->writeHTML('<div style="color:#F00; font-size: 9pt; font-weight: bold;"><br/>' .$notes. '<br/></div>', true, 0, true, 0);
 }

} while ($row_rs_media_group = mysql_fetch_assoc($rs_media_group));

if ($Num2++ != $totalRows_rs_media_category_list) {

$pdf->AddPage();

}


} while ($row_rs_media_category_list = mysql_fetch_assoc($rs_media_category_list));

//Close and output PDF document
$pdf->Output('Selectech_Price_List.pdf', 'I');

//============================================================+
// END OF FILE                                                 
//============================================================+

Answer : FPDF PDF Generator Support

you don't .

ask your provider too
Random Solutions  
 
programming4us programming4us