$items = array(item_load($db, $id)); if (!$items[0]) { die_json("No such item."); } } $trim = $_REQUEST['trim']; $left_margin = 0.2; $label_width = 2.0; $label_height = 0.75; $basefontsize = 9; $vmargin = 0.1; $dummy = new AlphaPDF('P', 'in', array($label_width, $label_height)); $pdf = new AlphaPDF('P', 'in', array($label_width, $label_height)); foreach ($items as $item) { $pdf->AddPage(); $pdf->Rotate(270); $pdf->SetFont('Helvetica', ''); $pdf->SetFontSize($size = $basefontsize); $pdf->SetTextColor(0); // write the name $name = utf8_decode($item['name']); if ($trim) { $name = preg_replace("/{$trim}/i", '', $name); } $width = $pdf->GetStringWidth($name); while ($width > $label_width - $left_margin * 2 && $size) { $pdf->SetFontSize(--$size); $width = $pdf->GetStringWidth($name); } $pdf->Text(($label_width - $width) / 2, $vmargin + $size / 72, $name); // write the prices