【发布时间】:2015-06-15 13:16:32
【问题描述】:
您好,我有一个使用套接字的 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。 理查德
【问题讨论】:
-
刚刚阅读了一些内容,这似乎很有趣。stackoverflow.com/questions/25280522/… 值得注意的是 PSDocOptions 和 PSPageOptions 函数
标签: php printing postscript tray