
		aller
		
		(usa Ubuntu)
		
		Enviado em 26/06/2013 - 13:21h 
		Sei que este tópico é antigo, mas também precisei solucionar este problema. Não posso dizer que minha solução é ideal, mas funciona.
Arquivo Index.php contém o exemplo de uso e teste.
<HTML>
<HEAD>
 <TITLE>Documento PHP</TITLE>
</HEAD>
<BODY>
<?
echo phpversion();
echo "<br>";
echo "<hr>";
echo "<h2>Teste impressao Aller_Printer - ".time()."</h2>";
echo "<hr>";
include("aller_printer.php");
$prn = new Aller_Printer();
echo "Nomes das impressoras: ".$prn->getList()."<br>";
echo "Quantidade de impressoras: ".$prn->getNumberOfPrinters()."<br>";
echo "<hr>";
echo "<b>Dados da impressora obtidos de: </b>".$prn->getInfoSource();
echo "<hr>";
echo "Teste de impressao na Lexmark-E120<br>";
echo "Esta impressora existe na minha rede e está compartilhada com o Linux<br>";
$retorno = $prn->imprimeArquivo("Lexmark-E120","/home/aller/site/teste/aller_impressao/index.php");
if (!$retorno){
   echo "Não foi possível imprimir o arquivo.<br>";
}
echo "<hr>";
echo "Verificacao<br>";
$prn->temp();
?>
</BODY>
</HTML>
A Classe Aller_Printer contém os parâmetros para impressão em si. Observe o que pode ser editado e o que não deve. Não vou explicar demasiadamente aqui. Veja os arquivos.
<?php
/* Aller_Printer
 * Direitos reservados: Aller Soft Co. (2003)
 * Author: Alex Leandro Rosa
 * E-mail: aller@aller.com.br
 *
 */
// Todas as impressoras nas quais o Linux podera imprimir devem
// estar adicionadas como compartilhamento nele.
// Veja o arquivo index.php para entender o uso.
class Aller_Printer{
   // Ajuste os enderecos abaixo de acordo com
   // seu servidor Linux.
   
   private $lp_location = "/usr/bin/lp";
   private $lpr_location = "/usr/bin/lpr";
   private $lpc_location = "/usr/sbin/lpc";
   private $printcap_location = "/etc/printcap";
   
   // Nao mexa daqui para baixo, a menos que saiba o que esta fazendo
   // Caso refatore, melhore, eh legitimo enviar suas melhorias para
   // o autor.
   private $prn_info_source = ""; // lpc -> obtido do comando lpc executado na shell
                                  // printcap -> obtido do arquivo /etc/printcap
   private  $printers_printcap = array(array(
                                "name" => "",
                                "device" => "",
                                "remote_machine" => "",
                                "remote_protocol" => ""
                                )
                             );
   private $prn_posicao_printcap= array(
                               "name",
                               "device",
                               "remote_machine",
                               "remote_protocol"
                               );
                               
   private  $printers_lpc = array(array(
                                "name" => "",
                                "device" => "",
                                "queuing" => "",
                                "printing" => "",
                                "entries" => "",
                                "daemon" => ""
                                )
                             );
   private $prn_posicao_lpc= array(
                               "name",
                               "device",
                               "queuing",
                               "printing",
                               "entries",
                               "daemon"
                               );
   public function __construct() {
      if( ini_get('safe_mode') ){
        echo "<b>Safe mode está ligado.</b><br>";
        echo "O sistema precisa que o Safe mode seja desligado para usar esta classe.<br>";
        exit(0);
      }
      
      if (!($this->printer_parser_printcap())){
         $this->printer_parser_lpc();
      }
   }
    
   public function getList(){
      $prn_list = "";
      if ($this->prn_info_source=="printcap"){
         foreach($this->printers_printcap as $printer){
            if (!empty($printer["name"])){
             $prn_list .= $printer["name"].",";
            }
         }
      } else {
         foreach($this->printers_lpc as $printer){
            if (!empty($printer["name"])){
             $prn_list .= $printer["name"].",";
            }
         }
      }
      if (!empty($prn_list)){
         $aux = substr($prn_list,0,strlen($prn_list)-1);
         $prn_list = $aux;
      }
      return $prn_list;
   }
   
   public function getNumberOfPrinters(){
      if ($this->prn_info_source=="printcap"){
         return count($this->printers_printcap);
      } else {
         return count($this->printers_lpc);
      }
   }
   public function getInfoSource(){
      return $this->prn_info_source;
   }
   
   public function imprimeArquivo($prn_dest,$prn_texto){
      if(file_exists($prn_texto)){
         $device = "";
         $remote_machine = "";
         $remote_protocol = "";
         if ($this->prn_info_source=="printcap"){
            foreach($this->printers_printcap as $printer){
               if ($printer["name"]==$prn_dest){
                  $device= $printer["name"];
                  $remote_machine= $printer["remote_machine"];
                  $remote_protocol= $printer["remote_protocol"];
               }
            }
         } else {
            foreach($this->printers_lpc as $printer){
               if ($printer["name"]==$prn_dest){
                  $device= $printer["name"];
                  $remote_machine= "";
                  $remote_protocol= "";
               }
            }
         }
         $str_device = "";
         $str_remote_machine = "";
         $str_remote_protocol = "";
         
         $pr_cmd = $this->lp_location;
         if(file_exists($pr_cmd)){
            if (!empty($device)){
               $str_device = " -d$device ";
            }
            if(gethostname()!=$remote_machine){
               if (!empty($remote_machine)){
                  $str_remote_machine = " -h $remote_machine ";
               }
               if (!empty($remote_protocol)){
                  $str_remote_protocol = "/$remote_protocol";
               }
            }
            $str_cmd = "nohup $pr_cmd $str_device $str_remote_machine$str_remote_protocol $prn_texto&";
            $ret_val = shell_exec($str_cmd);
         } else {
            $pr_cmd = $this->lpr_location;
            if(file_exists($pr_cmd)){
               if (!empty($device)){
                  $str_device = " -P $device ";
               }
               if(gethostname()!=$remote_machine){
                  if (!empty($remote_machine)){
                     $str_remote_machine = " -H $remote_machine ";
                  }
                  if (!empty($remote_protocol)){
                     $str_remote_protocol = "/$remote_protocol";
                  }
               }
               $str_cmd = "nohup $pr_cmd $str_device $str_remote_machine$str_remote_protocol $prn_texto&";
               $ret_val = shell_exec($str_cmd);
            } else {
               $ret_val = false;
            }
         }
      } else {
         $ret_val = false;
      }
      return $ret_val;
   }
   
   private function printer_parser_printcap(){
      $filename = $this->printcap_location;
      if(file_exists($filename)){
         $fp = fopen($filename, "r");
         $posicao = 0;
         $contador = 0;
         while($linha = fgets($fp)){
            if(substr($linha,0,1)!="#"){
               $temp_linha = explode("|",$linha);
               $this->printers_printcap[$contador]["name"] = $temp_linha[0];
               $seg_linha = $temp_linha[1];
               $que_seg_linha = explode(":",$seg_linha);
               for($posicao=0; $posicao<3; $posicao++){
                  $this->printers_printcap[$contador][$this->prn_posicao_printcap[($posicao+1)]] = $this->atrib_parser_printcap($que_seg_linha[($posicao)]);
               }
               $contador++;
            }
         }
         if($contador>=1){
            $this->prn_info_source = "printcap";
            return true;
         }
         fclose($fp);
      } else {
         return false;
      }
   }
   
   private function atrib_parser_printcap($at_ps_pc){
      $ret_val = $at_ps_pc;
      $pos = strpos($at_ps_pc,"=");
      if (!($pos === false)){
         $temp_str = explode("=",$at_ps_pc);
         $ret_val = $temp_str[1];
      }
      return $ret_val;
   }
   private function printer_parser_lpc(){
      $filename = $this->lpc_location;
      if(file_exists($filename)){
         $lpc_res = trim(shell_exec($filename.' status all'));
         if(!empty($lpc_res)){
            $ar_lpc = explode("\n", $lpc_res);
            $posicao = 0;
            $contador = 0;
            foreach($ar_lpc as $valor){
               if($posicao==0){
                  $this->printers_lpc[$contador]["name"] = substr($valor,0,strlen($valor)-1);
                  $posicao++;
               }else{
                     $this->printers_lpc[$contador][$this->prn_posicao_lpc[$posicao]] = $this->atrib_parser_lpc($valor);
                     $posicao++;
               }
            
               if($posicao == 6){
                  $posicao = 0;
                  $contador++;
               }
            }
            if($contador>=1){
               $this->prn_info_source = "lpc";
               return true;
            }
         }
      } else {
         return false;
      }
   }
   
   private function atrib_parser_lpc($atrib_valor){
      $ret_val = "";
      $pos = 0;
      $atrib_valor = trim($atrib_valor);
      $at_val = explode(" ", $atrib_valor);
      if ($at_val[1]=="is"){
         $pos = strpos($atrib_valor,"is") + 3;
         $ret_val = substr($atrib_valor,$pos,strlen($atrib_valor)-$pos);
      }else if ($at_val[1]=="entries"){
         $entries = ($at_val[0]!="no")?$at_val[0]:0;
         $ret_val = $entries;
      }else if ($at_val[0]=="daemon"){
         $ret_val = $at_val[1];
      }else{
         $ret_val = $atrib_valor;
      }
      return $ret_val;
   }
   
   public function set($prop,$value){
      $this->$prop = $value;
   }
   public function get($prop){
      return $this->$prop;
   }
   public function temp(){
      echo "<hr>";
      echo "<b>Printers Printcap:</b><br>";
      print_r($this->printers_printcap);
      echo "<br>";
      echo "<hr>";
      echo "<b>Printers LPC:</b><br>";
      print_r($this->printers_lpc);
      echo "<br>";
   }
}
?>