Skip to content

Instantly share code, notes, and snippets.

@Pax125
Forked from matteomattei/direct_print.php
Created March 15, 2018 05:04
Show Gist options
  • Save Pax125/8ff4b1d51b16e5b2abbe55028d1296b7 to your computer and use it in GitHub Desktop.
Save Pax125/8ff4b1d51b16e5b2abbe55028d1296b7 to your computer and use it in GitHub Desktop.
PHP script that executes lpr program
<?php
function print_labels($files)
{
$cmd = '/usr/bin/lpr -PDYMO_LabelWriter_450_Turbo -o PageSize=w102h252.1 -o PageRegion=w102h252.1 -o landscape -o page-left=10 -o page-top=10 -o page-right=0 -o page-bottom=0 -o Resolution=300dpi -o cupsDarkness=Normal -o scaling=100 '.$files;
$output = system($cmd, $ret);
if($ret!=0 || $output!='')
{
return 'ERR ['.$ret.']: '.$output;
}
$cmd = '/usr/bin/lpq -PDYMO_LabelWriter_450_Turbo | head -n1 | grep -q "is ready$"';
$idx=0;
while(TRUE)
{
$output = system($cmd, $ret);
if($idx > 120 && $ret!=0)
return $output;
if($ret==0)
return TRUE;
sleep(1);
$idx++;
}
return TRUE;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment