Вот ссылка на PDF, который выглядит точно так же, как ваше изображение:
Ссылка на файл этикетки штрих-кода embrasse-moi.com
И вот функция, которая его создала. Я использую tcpdf. Я создаю 3 строки текста, идентификатор, описание, цену, которую я ищу из моего подидида, так что этот код вам придется заменить. Я также передаю смещение строки / столбца для использования с avery5167, чтобы мы могли использовать все наклейки.
function printProductLabelsAvery5167($product_sub_ids, $quantities, $row_offset, $column_offset, $filename)
{
// Embrasse-moi.com
require_once('../../../3rdParty/tcpdf/config/lang/eng.php');
require_once('../../../3rdParty/tcpdf/tcpdf.php');
$pdf_file_name = $filename;
$subid = array();
$poc_title = array();
$color_price = array();
for($i=0;$i<sizeof($product_sub_ids);$i++)
{
$pos_product_sub_id = $product_sub_ids[$i];
$pos_product_id = getProductIdFromProductSubId($pos_product_sub_id);
for($qty=0;$qty<$quantities[$i];$qty++)
{
$subid[] = getProductSubIDName($pos_product_sub_id);
$poc_title[] = substr(getProductTitle($pos_product_id),0,48);
$color_price[] = substr(getProductSubIdColorDescription($pos_product_sub_id),0,38) . ' $' . number_format(getProductRetail($pos_product_id),2);
}
}
$margin_left = 0;
$margin_right = 0;
$margin_top = 0;
$margin_bottom = 0;
$cell_width = 1.75;
$cell_height = 0.5;
$cell_spacing = 0.3;
$columns = 4;
$rows = 20;
$line_spacing_adjust = 0.015;
$barcode_spacing_adjust = 0.1;
$barcode_height_adjust = 0.05;
$title = 'Avery 5167 template';
$subject = 'PO # 123';
$keywords = 'purchase order 123';
$page_orientation = 'P';
$page_format = 'LETTER';
$unit = 'in';
// create new PDF document
$pdf = new TCPDF($page_orientation, $unit, $page_format, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(COMPANY_NAME);
$pdf->SetAuthor(getUserFullName($_SESSION['pos_user_id']));
$pdf->SetTitle($title);
$pdf->SetSubject($subject );
$pdf->SetKeywords($keywords);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins($margin_left, $margin_top, $margin_right);
$pdf->SetAutoPageBreak(TRUE, $margin_bottom);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$preferences = array('PrintScaling' => 'None');
$pdf->setViewerPreferences($preferences);
$pdf->SetFont('helvetica', 'R', 5);
//barcode: 128a?
// define barcode style
$barcode_style = array(
'position' => '',
'align' => 'C',
'stretch' => false,
'fitwidth' => false,
'cellfitalign' => '',
'border' => false,
'hpadding' => '0',
'vpadding' => '0',
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255),
'text' => false,
'font' => 'helvetica',
'fontsize' => 4,
'stretchtext' => 0
);
// set border width
$pdf->SetLineWidth(0.01);
$pdf->SetDrawColor(0,0,0);
//$pdf->setCellHeightRatio(3);
$counter = 0;
//calculating the pages.... how many labels are to be printed on the sheet...
//how many labels are going on the first sheet?
$first_page_number_of_spots = ($rows)*($columns-($column_offset-1)) -($row_offset-1);
$number_of_labels = sizeof($subid);
if($number_of_labels <= $first_page_number_of_spots)
{
$pages = 1;
}
else
{
$lables_on_first_page = $first_page_number_of_spots;
$labels_remaining = $number_of_labels -$lables_on_first_page;
$number_of_spots_per_page = $rows*$columns;
$pages = ceil($labels_remaining/($number_of_spots_per_page)) + 1;
}
for($page=0;$page<$pages;$page++)
{
$pdf->AddPage();
for($col=$column_offset-1;$col<$columns;$col++)
{
for($row=$row_offset-1;$row<$rows;$row++)
{
if($counter< sizeof($subid))
{
//barcodes must be cap
$line1 = strtoupper($subid[$counter]);
$line2 = $poc_title[$counter];
$line3 = $color_price[$counter];
}
else
{
$line1 = '';
$line2 = '';
$line3 = '';
}
$counter++;
$x_spot = $cell_spacing + $col*$cell_width + $col*$cell_spacing;
$y_spot = $cell_height + $row*$cell_height;
$coords = 'X:'.$x_spot . ' Y:' .$y_spot;
$border = 0;
$border2 = 0;
//this is the cell that will allow allignment to sticker checking
$pdf->SetXY($x_spot, $y_spot);
$pdf->Cell($cell_width, $cell_height, '', $border, 0, 'C', 0, '', 0, false, 'T', 'M');
// CODE 128 A
$pdf->SetXY($x_spot+$barcode_spacing_adjust, $y_spot);
//cell to check the barcode placement
$pdf->Cell($cell_width-2*$barcode_spacing_adjust, $cell_height/2, '', $border, 0, 'C', 0, '', 0, false, 'T', 'M');
$pdf->write1DBarcode($line1, 'C128A', $x_spot+$barcode_spacing_adjust, $y_spot+$barcode_height_adjust, $cell_width-2*$barcode_spacing_adjust, $cell_height/2 - $barcode_height_adjust, 0.4, $barcode_style, 'N');
//the remaining 3 lines have to fit in 1/2 the sticker size
//$y_offset = $cell_height/2;
$pdf->SetXY($x_spot, $y_spot - 0*$line_spacing_adjust + 3/6*$cell_height);
$pdf->Cell($cell_width, $cell_height/6, $line1, $border2, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->SetXY($x_spot, $y_spot - 1*$line_spacing_adjust + 4/6*$cell_height);
$pdf->Cell($cell_width, $cell_height/6, $line2, $border2, 0, 'C', 0, '', 0, false, 'T', 'C');
$pdf->SetXY($x_spot, $y_spot -2*$line_spacing_adjust + 5/6*$cell_height);
$pdf->Cell($cell_width, $cell_height/6, $line3, $border2, 0, 'C', 0, '', 0, false, 'T', 'C');
//$pdf->writeHTMLCell($cell_width, $cell_height, $x_spot, $y_spot, $text_for_label, 1, 1, false, true, '', false);
// no work $pdf->MultiCell($cell_width, $cell_height, $text_for_label, 1, 'J', false, '','',true, 0, false, true, $cell_height, 'T', false);
}
$row_offset = 1;
}
$column_offset = 1;
}
//Close and output PDF document
$pdf->Output($pdf_file_name, 'D');
//============================================================+
// END OF FILE
//============================================================+
}