0.65, 'colW'=>3.4, 'colSpacing'=>0.4); $layout['Platos'] = array('marginLR'=>0.65, 'colW'=>7.2, 'colSpacing'=>0.0); $font = array(); $font['category'] = array ('family'=>'ArialBlack', 'style'=>'', 'size'=>13, 'color'=>'#ba3e46'); $font['catDesc'] = array ('family'=>'Arial', 'style'=>'', 'size'=>10); $font['item'] = array ('family'=>'PalatinoLinotype', 'style'=>'', 'size'=>12, 'color'=>'#b7484d'); $font['itemDesc'] = array ('family'=>'PalatinoLinotype', 'style'=>'', 'size'=>11); require (FPDF_PATH.'fpdf.php'); $pdf = new FPDF('P', 'in', 'Letter'); $pdf->AddFont('Arial','', 'arial.php'); $pdf->AddFont('ArialBlack','', 'ariblk.php'); $pdf->AddFont('PalatinoLinotype','','pala.php'); $pdf->SetMargins (0, 0, 0); $pdf->SetAutoPageBreak (FALSE); $pdfz = new FPDF('P', 'in', 'Letter'); // sandbox to determine multicell heights $pdfz->AddFont('Arial','', 'arial.php'); $pdfz->AddFont('ArialBlack','', 'ariblk.php'); $pdfz->AddFont('PalatinoLinotype','','pala.php'); $pdf->AddPage(); //print header $imgW = 1.375; $pdf->Image('images/printHeader.jpg', 0.75, $marginT+0.125, 7.0); $pdf->SetY(2.2); foreach ($meals as $meal) { if ($meal['name']=='Dinner') { foreach ($meal['categories'] as $category) { if ($category['name'] != 'Postres') { $pdf->SetXY (0.75, $pdf->GetY()+0.15); switch ($category['name']) { case 'Apertivos': setFont ($pdf, 'category'); $pdf->MultiCell (7.0, $font['category']['size']/72, strtoupper($category['name']), 0, 'C'); $pdf->SetY($pdf->GetY()+$font['category']['size']/72); $colTop = $pdf->GetY(); $hItems = array(); $hPrinted = 0; for ($i=1;$i<=2;$i++) { // first check heights to determine column breaks, then lay out section foreach ($category['items'] as $keyItem=>$item) { if ($item['special'] <> '1') { if ($i==1) { // tally total height of items to determine position of column break $pdfz->SetY(0); $hItems[$keyItem] = printItem ($pdfz, $item, 0, $layout[$category['name']]['colW']); } else { // print items if ($hPrinted < (array_sum($hItems)/2)) { $x = $layout[$category['name']]['marginLR']; } else { if ($x == $layout[$category['name']]['marginLR']) { $x = $layout[$category['name']]['marginLR'] + $layout[$category['name']]['colW'] + $layout[$category['name']]['colSpacing']; $pdf->SetY($colTop); } } $y = printItem ($pdf, $item, $x, $layout[$category['name']]['colW']); if ($y > $colBottom) { $colBottom = $y; } $hPrinted += $hItems[$keyItem]; } } } } $pdf->SetY($colBottom); break; case 'Platos': $isFirstItem = TRUE; foreach ($category['items'] as $keyItem=>$item) { if ($item['special'] <> '1') { if (is_numeric($item['prices'][0]['price'])) { $item['prices'][0]['price'] = str_replace('.00','',sprintf("$%01.2f", floatval($item['prices'][0]['price']))); } if ($isFirstItem) { $mainPrice = $item['prices'][0]['price']; setFont ($pdf, 'category'); $pdf->MultiCell (7.0, $font['category']['size']/72, (strtoupper($category['name']).' '.$mainPrice), 0, 'C'); $pdf->SetXY(0.75, $pdf->GetY()+0.1); setFont ($pdf, 'catDesc'); $pdf->MultiCell (7.0, $font['catDesc']['size']/72, stripslashes($category['desc']), 0, 'C'); $pdf->SetY($pdf->GetY()+$font['category']['size']/72); $isFirstItem = FALSE; } $y = $pdf->GetY(); setFont ($pdf, 'item'); $pdf->SetX ($layout[$category['name']]['marginLR']); $pdf->Cell($layout[$category['name']]['colW'], ($font['item']['size']+2)/72, $item['name']); // leave space in the item description MultiCell for the item name (different font/color) $w1 = $pdf->GetStringWidth(stripslashes($item['name'])); $numSpaces = 0; setFont ($pdf, 'itemDesc'); while ($pdf->GetStringWidth(str_repeat(' ',$numSpaces)) < $w1) { $numSpaces++; } $itemDesc = str_repeat(' ',++$numSpaces).str_replace("\n",' ',stripslashes($item['desc'])) .(($item['prices'][0]['price'] != $mainPrice) ? (' '.$item['prices'][0]['price']) : ''); setFont ($pdf, 'itemDesc'); $pdf->SetXY ($layout[$category['name']]['marginLR'], $y); $pdf->MultiCell ($layout[$category['name']]['colW'], ($font['itemDesc']['size']+2)/72, $itemDesc, 0, 'L'); $pdf->SetY($pdf->GetY()+$font['itemDesc']['size']/144); } } break; } } } } } $pdf->Output(); function setFont (&$pdf, $class) { global $font; $pdf->SetFont($font[$class]['family'], $font[$class]['style'], $font[$class]['size']); if ($font[$class]['color'] != '') { $pdf->SetTextColor(hexdec(substr($font[$class]['color'],1,2)), hexdec(substr($font[$class]['color'],3,2)), hexdec(substr($font[$class]['color'],5,2))); } else { $pdf->SetTextColor(0); } } function printItem (&$pdf, $item, $x, $colW) { global $font; $y = $pdf->GetY(); setFont ($pdf, 'item'); $pdf->SetX ($x); $pdf->Cell($colW, ($font['item']['size']+2)/72, $item['name']); // leave space in the item description MultiCell for the item name (different font/color) $w1 = $pdf->GetStringWidth(stripslashes($item['name'])); $numSpaces = 0; setFont ($pdf, 'itemDesc'); while ($pdf->GetStringWidth(str_repeat(' ',$numSpaces)) < $w1) { $numSpaces++; } if (is_numeric($item['prices'][0]['price'])) { $item['prices'][0]['price'] = str_replace('.00','',sprintf("$%01.2f", floatval($item['prices'][0]['price']))); } setFont ($pdf, 'itemDesc'); $pdf->SetXY ($x, $y); $pdf->MultiCell ($colW, ($font['itemDesc']['size']+2)/72, (str_repeat(' ',++$numSpaces).str_replace("\n",' ',stripslashes($item['desc'])).' '.$item['prices'][0]['price']), 0, 'L'); $pdf->SetY($pdf->GetY()+$font['itemDesc']['size']/144); return $pdf->GetY(); } /* // Create an AFM file from a TTF require ('includes/fpdf/font/makefont/makefont.php'); MakeFont('includes/fpdf/font/fonts/gothicb.ttf','includes/fpdf/font/fonts/gothicb.afm'); MakeFont('includes/fpdf/font/fonts/gothicbi.ttf','includes/fpdf/font/fonts/gothicbi.afm'); MakeFont('includes/fpdf/font/fonts/gothici.ttf','includes/fpdf/font/fonts/gothici.afm'); */ ?>