Здравейте, имам PHP решения за печат, използващи сокети. Използване на тази функция/клас.
public function printJob($queue){
//Private static function prints waiting jobs on the queue.
$this->printWaiting($queue);
//Open a new connection to send the control file and data.
$stream = stream_socket_client("tcp://".$this->host.":".$this->port, $this->errNo, $this->errStr, $this->timeout);
if(!$stream){
return $this->errNo." (".$this->errStr.")";
} else {
$job = self::getJobId();//Get a new id for this job
//Set printer to receive file
fwrite($stream, chr(2).$queue."\n");
$this->debug .= "Confirmation of receive cmd:".ord(fread($stream, 1))."\n";
//Send Control file.
(isset($_SERVER['SERVER_NAME'])) ? $server = $_SERVER['SERVER_NAME'] : $server = "me";//Might be CLI and not have _SERVER
$ctrl = "H".$server."\nPphp\nfdfA".$job.$server."\n";
fwrite($stream, chr(2).strlen($ctrl)." cfA".$job.$server."\n");
$this->debug .= "Confirmation of sending of control file cmd:".ord(fread($stream, 1))."\n";
fwrite($stream, $ctrl.chr(0)); //Write null to indicate end of stream
$this->debug .= "Confirmation of sending of control file itself:".ord(fread($stream, 1))."\n";
if (is_readable($this->data)){
//It's a filename, rather than just some ascii text that needs printing. Open and stream.
if (strstr(strtolower($_ENV["OS"]), "windows")){
$this->debug .= "Operating system is Windows\n";
$data = fopen($this->data, "rb");//Force binary in Windows.
} else {
$this->debug .= "Operating system is not Windows\n";
$data = fopen($this->data, "r");
}
fwrite($stream, chr(3).filesize($this->data)." dfA".$job.$server."\n");
$this->debug .= "Confirmation of sending receive data cmd:".ord(fread($stream, 1))."\n";
while(!feof($data)){
fwrite($stream, fread($data, 8192));
}
fwrite($stream, chr(0));//Write null to indicate end of stream
$this->debug .= "Confirmation of sending data:".ord(fread($stream, 1))."\n";
fclose($data);
} else {
//Send data string
fwrite($stream, chr(3).strlen($this->data)." dfA".$job.$server."\n");
$this->debug .= "Confirmation of sending receive data cmd:".ord(fread($stream, 1))."\n";
fwrite($stream, $this->data.chr(0)); //Write null to indicate end of stream
$this->debug .= "Confirmation of sending data:".ord(fread($stream, 1))."\n";
}
}
}
Всичко е наред с него, но изглежда не мога да контролирам източника на хартия/тавата, която след това принтерът избира. Някой знае ли как се прави това?
Или може би различно решение, което използвам, харесвам това, защото мога да изпратя ip адреса (няма нужда от инсталиране), postscript файла и той се разпечатва. Така че, ако има друго решение, което изисква същите неща, тогава мога да използвам това.
Използвам PHP, iis, windows. Ричард