我有一个运行票房服务的网站,可以发行门票和报告.我想弄清楚如何将票证(当前为 PDF)直接发送到本地/客户端 PC 上的指定打印机.
I have a website which runs a box office service which issues tickets and reports. I am trying to figure out how to get tickets (currently PDFs) sent directly to a specified printer on a local/client PC.
我已经关注了许多旧的/死的/无用的链接,但没有找到任何最新的解决方案,尽管有许多诱人的希望.
I have followed many old/dead/useless links and have not found any up-to-date solutions to this although many tantalising glimmers of hope.
场景是这样的:远程托管网站 - 连接了 1 个或多个用户 - 网页生成票证/s (PDF),以静默方式发送到用户电脑上的指定打印机(不是默认打印机)(无需额外点击打印提示).
The scenario is this: Remote hosted website - 1 or more users connected - web page generates ticket/s (PDF) which is sent to a specified printer on the user pc (not the default printer) silently (no extra clicking through of print prompts).
我知道 PHP 无法连接到客户端的 pc,但是有没有办法让网页(可能通过 jQuery)连接到已安装的脚本/服务?
I know PHP does not connect to a clients pc but is there a way for a web page (via jQuery perhaps) to connect to an installed script/service?
我在想本地 PC 上的脚本(它建立可信链接、设置要使用的打印机等)会从 Web 服务器接收数据/文件,然后只要它在同一位置就可以处理它每台机器.然后可以将此(本地)脚本添加到需要运行该服务的任何 PC.这项工作需要由正在发送的文件触发,并且没有脚本/服务每隔几秒轮询一个位置.
I was thinking the script on a local PC (which establishes a trusted link, sets the printer to use, etc) would receive data/file from the web server and then process it as long as it was in the same place on every machine. This (local) script then can be added to any PC that needs to run the service. The work would need to be trigged by the file being sent and not having a script/service which is sat polling a location every few seconds.
任何指针将不胜感激.
我尝试过 jZebra java 小程序,但在它坏掉之前只打印了一次.有兴趣是否有人真正让它工作(以及如何工作).
I have tried the jZebra java applet but only got it printing once before it broke. Interested if anyone has actually got it to work (and how).
我最近遇到了完全相同的问题.谷歌浏览器具有所谓的信息亭"模式.因此,它将在没有用户干预的情况下打印.
I ran into the EXACT same question recently myself. Google Chrome has what's called a "kiosk" mode. Therefore, it will print without user intervention.
为此,请使用以下命令打开 Google Chrome(您需要找到 chrome 可执行文件,或 *nix 机器的 chrome 命令):
To do this, open Google Chrome with the following command (you need to find the chrome executable, or chrome command for *nix machines):
chrome.exe "http://www.example.com/mypage.php" --kiosk --kiosk-printing
这将打开一个没有任何工具栏、地址栏、多功能框等的窗口.
This will open a window without any toolbars, address bars, omniboxes, etc.
接下来,您需要打印页面.为此,请自动打开一个打印对话框(为了演示,我将使用简单的 Javascript):
Next, you need to make a page print. To do this, automatically open a print dialog (for demonstration, I'll use simple Javascript):
<script>
window.print();
</script>
在跳转到开发环境之前,window.print()
确实不允许允许任何参数(即 URL).
Before you jump over to your development environment, window.print()
does NOT allow any arguments (i.e. a URL).
此代码打开一个打印对话框.但是,在 kiosk 模式下,打印对话框将被绕过,页面将自动打印到默认打印机.
This code opens a print dialog. However, in kiosk mode, the print dialog will be bypassed, and the page will be automatically printed to the default printer.
现在您提到了一个 PDF,并且很有可能是您通过 PHP 生成它(如果您正在打印发布/生成的文件),您可能会想哦,我不能在 PDF 中放入 HTML 来执行 javascript".您不需要!要解决打印正确页面的问题,方法如下:
Now you mentioned a PDF, and chances are, your generating it via PHP (if you are printing issued/generated files), your probably thinking "oh, well I can't put HTML in the PDF to execute the javascript". You don't need to! To solve the issue of printing the correct page, here's how:
将以下内容插入到用户发送到的 HTML/PHP 页面中(对于此解决方案,用户不需要访问 .pdf),在 ;
登陆/成功页面:
Insert the following into an HTML/PHP page that the user is sent to (for this solution, the user does not need to visit the .pdf), in the <head>
of the landing/success page:
<link rel="alternate" media="print" href="LINK TO PDF FILE">
如果你的页面中有上面的代码,当你执行window.print();
时,它会打印上面指定的页面.如果您不在本地保存 PDF,您可以将它放在一个临时目录中,该目录以某种方式(超出本问题的范围)按基于时间或基于操作的计划清除,以防止磁盘空间增加.
If you have the above code in your page, when you execute window.print();
, it will print the page specified above. If you don't save the PDF locally, you can put it in a temporary directory that is somehow (out of the scope of this question) cleared on a time based or action based schedule, to prevent disk space buildup.
请记住以下几点:
ALT + F4
.--kiosk
AND --kiosk-printing
.打印参数需要 --kiosk
参数.ALT + F4
.--kiosk
AND --kiosk-printing
. The printing argument requires the --kiosk
argument.我确信其他浏览器也有类似的功能来绕过打印对话框,但是,我发现谷歌浏览器在这种功能中效果最好.如果您在 Linux 机器上,Google 有一个 .deb 文件,您可以使用该命令在 Linux 上安装 Google Chrome,使用命令 sudo dpkg -i(包/下载的 .deb 文件路径)
.Chromium -- 可能 -- 支持这种功能.据我所知,应该.
I'm sure that other browsers have similar functionality to bypass the print dialog, however, I have found that Google Chrome works best in this kind of functionality. If your on a Linux machine, Google has a .deb file that you can install Google Chrome on Linux with, by using the command sudo dpkg -i (package / downloaded .deb file path)
. Chromium --might-- support this kind of functionality. As far as I know, it should.
如果您需要其他帮助,请在下面的评论中留下您的问题,我会尽快回复.
If you need additional help, leave your question in the comments below, I'll respond ASAP.
我希望我有所帮助.如果我这样做了,请随时给我一张你左边的绿色支票.;)
I hope I helped. If I did, feel free to give me a green check to your left. ;)
这篇关于POS:让网站直接打印到定义的本地打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!