PHP服务器端打印Ubuntu服务器 [英] PHP Server Side Printing Ubuntu Server

查看:131
本文介绍了PHP服务器端打印Ubuntu服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处都在寻找执行此操作所需的内容,并且感到有些困惑.

I have been all over stack looking at what is required to do this and have wound up being slightly confused.

让我们直接了解一下这是一个基于本地的Intranet,我确实知道PHP是服务器端的.

Lets get one thing straight this is a local based intra-net and I do understand that PHP is server side.

我正在基于Web的PHP,JAVA,Jquery Idea上运行公司管理解决方案.并且我们想直接从"LINUX"服务器和收据等中打印报告.

I am running a company management solution on a web based PHP,JAVA,Jquery Idea. and we would like to print reports directly from the "LINUX" server and receipts etc.

我已经在服务器上安装了杯子,并且服务器可以正常打印,现在我只是停留在是否实际上可以让服务器打印我们直接从PHP代码生成的pdf文件的问题上.

I have installed cups on the server and the server is printing fine and I am now just stuck on whether or not it is actually possible to get the server to print our pdf files we are generating directly from the PHP code.

即使我们可以运行bash脚本并检查目录以打印pdf然后删除它,我也很高兴,即使我暂时认为这是可以解决的.

I would be happy even if we had a bash script to run and check a directory print the pdf and then delete it, even though I would see this as a work around for the time being.

就像我说的那样,我确实理解,如果这是在WWW上完成的,那么将可以使用某些漏洞利用.如果我要在www上运行该系统,我将拥有一个完全不同的站点,该站点不允许打印,并且不需要此功能.

Like I said I do understand that if this was done on the WWW then there would be certain exploits that could be used. If I were to run this system on the www I would have a totally different site that did not allow printing and this function would not be necessary.

提前谢谢

亚历克斯

推荐答案

如果CUPS的配置正确,那么从外壳打印PDF就很容易

If CUPS is configured properly, printing a PDF from the shell is literally as easy as

lpr myfile.pdf

因此,一旦将PDF写入临时文件,就可以使用任何可用的PHP函数来执行该Shell命令:exec()shell_exec()system()

So, once you have written your PDF to a temporary file, you can use any of the available PHP functions to execute that shell command: exec(), shell_exec(), system()

您甚至可以在不编写临时文件的情况下执行此操作,并通过STDIN将数据直接输入到lpr(在shell上以cat myfile.pdf | lpr为例)

You could even do it without writing a temporary file and feed the data directly to lpr via STDIN (try cat myfile.pdf | lpr as an example on the shell).

如果使用proc_open()运行程序,则可以使用PHP将数据提供给程序的STDIN.可以将 PHP手册中的第一个示例修改为类似这个:

You can feed data to a program's STDIN in PHP if you run it using proc_open(). The first example from the PHP Manual can be adapted to something like this:

<?php
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
);

$process = proc_open('lpr', $descriptorspec, $pipes);

if (is_resource($process)) {
    // $pipes now looks like this:
    // 0 => writeable handle connected to child stdin
    // 1 => readable handle connected to child stdout
    // Any error output will be appended to /tmp/error-output.txt

    fwrite($pipes[0], $pdf_data);
    fclose($pipes[0]);
}
?>

这篇关于PHP服务器端打印Ubuntu服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆