首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php打印解决方案中选择纸张源

在php打印解决方案中选择纸张源
EN

Stack Overflow用户
提问于 2015-06-15 13:16:32
回答 2查看 1.3K关注 0票数 2

嗨,我有一个PHP打印解决方案使用套接字。使用这个函数/类。

代码语言:javascript
复制
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。理查德

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-18 10:37:04

我认为这更多地是一个关于您正在使用的操作系统上的打印系统的问题(您似乎没有说明这是什么)。我也看不出打印作业发生在哪里,这是C#代码吗?

所有打印机都有属性,其中包括类似托盘设置的内容。在打印时,您需要配置设备,每个操作系统执行的步骤都不同。例如,在8+上,您需要设置一个作业票。我不记得它是如何在早期版本的Windows上完成的,我记得这是一个复杂的结构。在Linux上,这将取决于您是否使用CUPS,如果使用,您可能需要为您想要使用的特定托盘设置CUPS管道。

我看到有一些代码测试来查看操作系统是Windows还是其他东西。我想你需要弄清楚里面该怎么做。

后加

好的,现在我更明白你在做什么。由于您正在使用Ghostscript从您的PostScript文件创建,这个问题确实更有意义。

上面提到的链接以及PSDocOptions和PSPageOptions是您所需要的,结合luser_droog关于托盘选择的要点。

因此,首先,您需要找出您的打印机希望以PostScript的方式,以改变托盘。您的PPD文件包含了这些内容:

代码语言:javascript
复制
*InputSlot Internal/Cassette 1 (Internal): "<</ManualFeed false>> setpagedevice statusdict begin 0 setpapertray end"
*InputSlot PF60A/Cassette 2: "<</ManualFeed false>> setpagedevice statusdict begin 1 setpapertray end"
*InputSlot PF60B/Cassette 3: "<</ManualFeed false>> setpagedevice statusdict begin 4 setpapertray end"
*InputSlot PF60C/Cassette 4: "<</ManualFeed false>> setpagedevice statusdict begin 5 setpapertray end"
*InputSlot EF1/Envelope Feeder: "<</ManualFeed false>> setpagedevice statusdict begin 2 setpapertray end"

因此,要选择‘盒式’1,所需的PostScript是:

代码语言:javascript
复制
<</ManualFeed false>> setpagedevice statusdict begin 0 setpapertray end

现在假设您使用的是最近的Ghostscript版本(即至少9.16版本),那么您可以将其添加到PostScript命令行中;

代码语言:javascript
复制
-dPSDocOptions="<</ManualFeed false>> setpagedevice statusdict begin 0 setpapertray end"

它将在开始作业之前将当前托盘设置为托盘1。请注意,您的PostScript文件不再是设备独立的,它现在只能可靠地工作在这类打印机上。

如果你想(例如)第1页印在磁带1上,第2页印在录音带2上,你就需要使用PSPageOptions,例如:

代码语言:javascript
复制
    -dPSpageOptions=["<</ManualFeed false>> setpagedevice statusdict begin 0 setpapertray end"
 "<</ManualFeed false>> setpagedevice statusdict begin 1 setpapertray end"]

我假设你是在一个特定的组织中部署这个项目,而不是向世界开放。不过,最好在某个地方贴上Ghostscript已获得AGPL许可的注释,如果这是作为一项通用服务提供的,那么可能必须提供整个源代码( AGPL涵盖软件作为服务)。

票数 2
EN

Stack Overflow用户

发布于 2015-06-17 15:09:54

这将需要打印机特定的postscript代码。您应该搜索需要使用的特定打印机的.PPD文件(postscript打印机定义)。

.ppd文件是一种特殊格式的ascii文本,但易于人类阅读.打印机的任何特殊功能,如果不能在标准postscript中完成(但仍然可以用postscript实现),都会以这种方式记录下来。

我在过去做过类似的打印,使用unix telnet命令指定ip地址和端口,并将输入重定向为我的ps文件。使用命令行telnet程序的windows shell也应该是一样的.

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30846194

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档