Jump to Navigation

012 - How to print a label from Zebra printer

This is a sample program in order to print a label from zebra printer.
Once You make printer codes in a LBL file, You can print it by shell_exec().

Example:


profile_load_profile($user); 
$print_res = TRUE;
if ($user->uid == 1) {
//    $printer = variable_get('printer_name', 1);
//    $p_ip_address = variable_get('p_ip_address', 1);
$printer = 'HP5000KMS';   
$p_ip_address = '10.200.3.52';
}else{
$printer = $user->profile_printer;
$p_ip_address = $user->profile_ip_address;
}
$vals1 = $GLOBALS['vals1'];
$vals2 = $GLOBALS['vals2'];
$output1 ="! 0 200 200 800 1\r\n";
$output1 .= "LABEL\r\n";
$output1 .= "CONTRAST 0\r\n";
$output1 .= "TONE 0\r\n";
$output1 .= "SPEED 3\r\n";
$output1 .= "PAGE-WIDTH 800\r\n";
$output1 .= "BAR-SENSE\r\n";
$output1 .= ";// PAGE 0000000008000800\r\n";
$output1 .= "T 5 2 27 115 " . $GLOBALS['prod_id'] . "\r\n";
$output1 .= "T 5 0 140 130 " . $GLOBALS['prod_desc']. "\r\n";
$output1 .= "T 5 2 270 290 " . $vals1[0][0] . "\r\n";
$output1 .= "T 5 2 270 230 050\r\n";
$output1 .= "T 5 0 25 230 ZONE :\r\n";
$output1 .= "T 5 0 26 300 Primary Loc :\r\n";
$output1 .= "T 5 0 26 370 Secondary Loc :\r\n";
$output1 .= "LINE 26 200 780 200 3\r\n";
$output1 .= "T 5 0 60 50 PHYSICAL PUTAWAY (CYCLE COUNT REQUIRED)\r\n";
$output1 .= "T 5 2 270 360 " . $vals2[0][0] . "\r\n";
$output1 .= "T 5 2 270 405 " . $vals2[1][0] . "\r\n";
$output1 .= "T 5 2 270 450 " . $vals2[2][0] . "\r\n";
$output1 .= "T 5 0 600 300 (CS QTY=" . number_format($vals1[0][1],0). ")\r\n";
$output1 .= "T 5 0 600 375 (CS QTY=" . number_format($vals2[0][1],0) . ")\r\n";
$output1 .= "T 5 0 600 420 (CS QTY=" . number_format($vals2[1][1],0) . ")\r\n";
$output1 .= "T 5 0 600 465 (CS QTY=" . number_format($vals2[2][1],0) . ")\r\n";
$output1 .= "FORM\r\n";
$output1 .= "PRINT\r\n";
$filename = "c:\\temp\\exacta.LBL";
if (file_exists($filename)) {
if (unlink($filename)) {
print "Deleted $filename!\n";
} else {
echo "Deleted of $filename failed!!\n";
$print_res = FALSE;
}
} else {
$print_res = FALSE;
echo "$filename does not exists!\n";
}
if (!$handle = fopen($filename, "w")) {
$print_res = FALSE;
echo "Can not open $filename !!\n";
}
if (fwrite($handle, $output1) === FALSE) {
$print_res = FALSE;
echo "Can not write $filename !!\n";
}
fclose($handle);
// $output2 = shell_exec("lpr -S 10.0.203.51 -P HP4000JFC -d $filename");
// RF gun & Printer Mapping in user profile settings.
$output2 = shell_exec("lpr -S $p_ip_address -P $printer -d $filename");
return $print_res;

 

 

drupal:


Main menu 2

Story | by Dr. Radut