Witam,
mam taki problem.
Używam TCPDF do generowania katalogu produktów ze sklepu.
Ze względu na to że opisy produktów są różnej długości nie jestem w stanie ręcznie wskazać po ilu wyświetlonych produktach, kolejny powinien być wyświetlony na następnej stronie, tak aby go nie podzieliło na 2 strony (ucięło)
Czy jest możliwość wykrycia kiedy dany element nie zmieści się w całości na stronie i przenieść go już na następną?
Tak wygląda mój kod:
<?php
include_once('cms/config.php');
include_once('cms/class/db_manager.php');
require_once('tcpdf/examples/tcpdf_include.php');
class MYPDF extends TCPDF {
$this->setPageMark();
$image_file = K_PATH_IMAGES.'Logo2.png';
$this->Image($image_file, 0, 0, 40, '', 'PNG', '', 'C', false, 300, 'C', false, false, 0, false, false, false);
}
public function Footer() {
$this->SetY(-15);
$this->SetFont('helvetica', 'I', 8);
$this->Cell(0, 10, 'Frykas Wine Collection ul. Freta 49/51 00-227 Warszawa Tel: 123 456 789 E-mail: kontakt@frykaswine.pl', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 20, $this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// 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 (optional)
require_once(dirname(__FILE__).'/lang/eng.php'); $pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('freeserif', '', 12);
// set some text to print
$txt1 = <<<EOD
<!-- EXAMPLE OF CSS STYLE -->
<style>
div.test {
color: #64624d;
font-family: times;
font-size: 20pt;
}
</style>
EOD;
$pdf->SetPrintHeader(true);
$pdf->AddPage();
$pdf->writeHTML($txt1, true, false, true, false,'C');
$filter = $_GET['f'];
$obj = new db_manager();
foreach($products as $p){
$cat_name = $obj->selectBySQL("SELECT * FROM fr_products_category WHERE id='".$p."'");
$conn = $obj->getConnection();
$r_products = $conn->query("SELECT DISTINCT fr_product.*,fr_product_filter.filter_value FROM fr_product INNER JOIN fr_product_filter ON fr_product.code = fr_product_filter.product_code WHERE fr_product_filter.filter_id='".$filter."' AND fr_product.products_category='".$p."' GROUP BY fr_product.code ORDER BY fr_product_filter.filter_value ASC");
$txt_title = '
<style>
h2{
text-transform: uppercase;
color: #52503d;
font-size:30px;
}
</style>
<br>
<h2>'.$cat_name[0]['name'].'</h2>
<br>
<br>
<br>
';
//echo'<h2>'.$cat_name[0]['name'].'</h2>';
$pdf->AddPage();
$pdf->writeHTML($txt_title, true, false, true, false,'C');
$k=0;
while ($r = mysqli_fetch_array($r_products)) {
$filters_name=$conn->query("SELECT DISTINCT fr_product_filter.*, fr_filters.name FROM fr_product_filter INNER JOIN fr_filters ON fr_product_filter.filter_id = fr_filters.id WHERE fr_product_filter.product_code='".$r['code']."'");
$txt = '
<!-- EXAMPLE OF CSS STYLE -->
<style>
td{
vertical-align: middle;
font-size: 12px;
text-align: left;
position:relative;
}
td.img{
width: 200px;
text-align: center;
}
td.text{
width:430px;
}
div.name{
text-aling:center;
font-size:20px;
}
div.code{
font-size:9px;
}
div.desc{
font-size:11px;
}
div.price{
font-size:17px;
}
div.info{
font-size:10px;
}
table{
border-bottom:1px solid #c7c7a1;
border-left:1px solid #c7c7a1;
}
</style>
<table>
<tr>
<td class="img"><img src="' .$r['image'].'" alt="" height="200px;"/></td>
<td class="text">';
$txt .= '<div class="name">'.$r['name'].'</div>';
$txt .= '<div class="code">'.$r['code'].'</div>';
if(in_array('description',$info_general)) $txt .= '<div class="desc">'.$r['description'].'</div>';
$txt .= '<div class="price">'.$r['price'].' zł</div>';
$txt .='<div class="info">';
//foreach($filters_name as $fn){
while ($fn = mysqli_fetch_array($filters_name)) {
if(trim($fn['filter_value'])!='') $txt .= '<b>'.$fn['name'].'</b>: '.$fn['filter_value'].'<br/>';
}
}
$txt .= '</div></td>
</tr>
</table>
';
$pdf->writeHTML($txt, true, false, true, false,'C');
$k++;
}
}
$pdf->SetPrintHeader(true);
$pdf->AddPage();
$pdf->writeHTML($txt1, true, false, true, false,'C');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('Frykas Wine Collection - katalog produktow.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+