Hi I've got a PHP printing solutions using sockets. Using this function/class.
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."
");
$this->debug .= "Confirmation of receive cmd:".ord(fread($stream, 1))."
";
//Send Control file.
(isset($_SERVER['SERVER_NAME'])) ? $server = $_SERVER['SERVER_NAME'] : $server = "me";//Might be CLI and not have _SERVER
$ctrl = "H".$server."
Pphp
fdfA".$job.$server."
";
fwrite($stream, chr(2).strlen($ctrl)." cfA".$job.$server."
");
$this->debug .= "Confirmation of sending of control file cmd:".ord(fread($stream, 1))."
";
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))."
";
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
";
$data = fopen($this->data, "rb");//Force binary in Windows.
} else {
$this->debug .= "Operating system is not Windows
";
$data = fopen($this->data, "r");
}
fwrite($stream, chr(3).filesize($this->data)." dfA".$job.$server."
");
$this->debug .= "Confirmation of sending receive data cmd:".ord(fread($stream, 1))."
";
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))."
";
fclose($data);
} else {
//Send data string
fwrite($stream, chr(3).strlen($this->data)." dfA".$job.$server."
");
$this->debug .= "Confirmation of sending receive data cmd:".ord(fread($stream, 1))."
";
fwrite($stream, $this->data.chr(0)); //Write null to indicate end of stream
$this->debug .= "Confirmation of sending data:".ord(fread($stream, 1))."
";
}
}
}
All is well with it but I can't seem to control the paper source/tray that the printer then selects. Does anyone know how to do this?
Or perhaps a different solution that I an use, I like this one because I can send the ip address (no need for install), postscript file and it prints out. So if there is another solution that requires the same things then I can use that.
I'm using PHP, iis, windows. Richard