Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]TCPDF i przenienie tresci na kolejną stronę
Forum PHP.pl > Forum > Przedszkole
kamilo818
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:

  1. <?php
  2. include_once('cms/config.php');
  3. include_once('cms/class/db_manager.php');
  4.  
  5. require_once('tcpdf/examples/tcpdf_include.php');
  6.  
  7.  
  8. class MYPDF extends TCPDF {
  9.  
  10. public function Header() {
  11.  
  12. $this->setPageMark();
  13.  
  14. $image_file = K_PATH_IMAGES.'Logo2.png';
  15. $this->Image($image_file, 0, 0, 40, '', 'PNG', '', 'C', false, 300, 'C', false, false, 0, false, false, false);
  16.  
  17. }
  18.  
  19. public function Footer() {
  20.  
  21. $this->SetY(-15);
  22.  
  23. $this->SetFont('helvetica', 'I', 8);
  24.  
  25. $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');
  26.  
  27. $this->Cell(0, 20, $this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
  28.  
  29. }
  30. }
  31.  
  32. $pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  33.  
  34.  
  35.  
  36. // set default header data
  37. $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  38.  
  39. // set header and footer fonts
  40. $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  41. $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  42.  
  43. // set default monospaced font
  44. $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  45.  
  46. // set margins
  47. $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  48. $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
  49. $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
  50.  
  51. // set auto page breaks
  52. $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  53.  
  54. // set image scale factor
  55. $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
  56.  
  57. // set some language-dependent strings (optional)
  58. if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
  59. require_once(dirname(__FILE__).'/lang/eng.php');
  60. $pdf->setLanguageArray($l);
  61. }
  62.  
  63. // ---------------------------------------------------------
  64.  
  65. // set font
  66. $pdf->SetFont('freeserif', '', 12);
  67.  
  68.  
  69. // set some text to print
  70. $txt1 = <<<EOD
  71. <!-- EXAMPLE OF CSS STYLE -->
  72. <style>
  73.  
  74. div.test {
  75. color: #64624d;
  76.  
  77. font-family: times;
  78. font-size: 20pt;
  79.  
  80.  
  81. }
  82.  
  83. </style>
  84.  
  85.  
  86.  
  87.  
  88. EOD;
  89.  
  90.  
  91. $pdf->SetPrintHeader(true);
  92. $pdf->AddPage();
  93. $pdf->writeHTML($txt1, true, false, true, false,'C');
  94.  
  95. $products = array_filter(explode(',',$_GET['p']));
  96. $filter = $_GET['f'];
  97. $info = array_filter(explode(',',$_GET['i']));
  98. $info_general = array_filter(explode(',',$_GET['ig']));
  99.  
  100.  
  101.  
  102. $obj = new db_manager();
  103.  
  104. foreach($products as $p){
  105.  
  106. $cat_name = $obj->selectBySQL("SELECT * FROM fr_products_category WHERE id='".$p."'");
  107.  
  108. $conn = $obj->getConnection();
  109. $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");
  110.  
  111.  
  112.  
  113. $txt_title = '
  114. <style>
  115. h2{
  116. text-transform: uppercase;
  117. color: #52503d;
  118. font-size:30px;
  119. }
  120. </style>
  121. <br>
  122. <h2>'.$cat_name[0]['name'].'</h2>
  123. <br>
  124. <br>
  125. <br>
  126. ';
  127.  
  128. //echo'<h2>'.$cat_name[0]['name'].'</h2>';
  129. $pdf->AddPage();
  130. $pdf->writeHTML($txt_title, true, false, true, false,'C');
  131. $k=0;
  132.  
  133. while ($r = mysqli_fetch_array($r_products)) {
  134.  
  135. $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']."'");
  136.  
  137. $txt = '
  138. <!-- EXAMPLE OF CSS STYLE -->
  139. <style>
  140.  
  141. td{
  142. vertical-align: middle;
  143. font-size: 12px;
  144. text-align: left;
  145. position:relative;
  146. }
  147. td.img{
  148. width: 200px;
  149. text-align: center;
  150. }
  151. td.text{
  152. width:430px;
  153. }
  154.  
  155. div.name{
  156. text-aling:center;
  157. font-size:20px;
  158. }
  159. div.code{
  160. font-size:9px;
  161. }
  162. div.desc{
  163. font-size:11px;
  164. }
  165. div.price{
  166. font-size:17px;
  167. }
  168. div.info{
  169. font-size:10px;
  170. }
  171. table{
  172. border-bottom:1px solid #c7c7a1;
  173. border-left:1px solid #c7c7a1;
  174. }
  175.  
  176. </style>
  177. <table>
  178. <tr>
  179. <td class="img"><img src="' .$r['image'].'" alt="" height="200px;"/></td>
  180. <td class="text">';
  181.  
  182. $txt .= '<div class="name">'.$r['name'].'</div>';
  183. if(in_array('code',$info_general))
  184. $txt .= '<div class="code">'.$r['code'].'</div>';
  185. if(in_array('description',$info_general))
  186. $txt .= '<div class="desc">'.$r['description'].'</div>';
  187. if(in_array('price',$info_general))
  188. $txt .= '<div class="price">'.$r['price'].' zł</div>';
  189. $txt .='<div class="info">';
  190. //foreach($filters_name as $fn){
  191. while ($fn = mysqli_fetch_array($filters_name)) {
  192. if(in_array($fn['filter_id'],$info)){
  193. if(trim($fn['filter_value'])!='')
  194. $txt .= '<b>'.$fn['name'].'</b>: '.$fn['filter_value'].'<br/>';
  195. }
  196.  
  197. }
  198. $txt .= '</div></td>
  199.  
  200. </tr>
  201. </table>
  202.  
  203. ';
  204.  
  205.  
  206.  
  207. $pdf->writeHTML($txt, true, false, true, false,'C');
  208. $k++;
  209.  
  210.  
  211. }
  212.  
  213.  
  214. }
  215.  
  216.  
  217. $pdf->SetPrintHeader(true);
  218. $pdf->AddPage();
  219. $pdf->writeHTML($txt1, true, false, true, false,'C');
  220.  
  221.  
  222. // ---------------------------------------------------------
  223.  
  224. //Close and output PDF document
  225. $pdf->Output('Frykas Wine Collection - katalog produktow.pdf', 'I');
  226.  
  227. //============================================================+
  228. // END OF FILE
  229. //============================================================+
  230.  
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.