POS:获取网站以直接打印到已定义的本地打印机 [英] POS: get a website to print directly to a defined local printer/s

查看:177
本文介绍了POS:获取网站以直接打印到已定义的本地打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行票房和票务服务的网站.我试图弄清楚如何将票证(当前为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个或更多用户-网页生成票证(PDF),该票证将以静默方式发送到用户PC上的指定打印机(不是默认打印机)(无需额外点击)打印提示).

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).

推荐答案

最近我本人也遇到了完全相同的问题. Google Chrome具有所谓的信息亭"模式.因此,它将在没有用户干预的情况下打印.

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.

为此,请使用以下命令打开Goog​​le 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).

此代码将打开一个打印对话框.但是,在信息亭模式下,将跳过打印对话框,并且页面将自动打印到默认打印机.

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生成的(如果您正在打印发布/生成的文件),您可能会想:哦,好吧,我不能在HTML中放入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:

在登录页面的<head>中,将以下内容插入用户发送到的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 --kiosk-printing.打印参数需要 --kiosk参数.
  • 在信息亭模式下打印时,出现打印对话框然后突然消失是正常.没有高级的窗口分层和其他功能,这是无法避免的.
  • Kiosk mode doesn't have an exit button. To exit, press ALT + F4.
  • When printing in kiosk mode, you need both --kiosk AND --kiosk-printing. The printing argument requires the --kiosk argument.
  • When printing in kiosk mode, it is normal for the print dialog to appear and then suddenly disappear. It can't be prevented without advanced window layering and whatnot.

我确定其他浏览器也具有类似的功能来绕过打印对话框,但是,我发现Google Chrome浏览器在这种功能中效果最好.如果您使用的是Linux计算机,则Google拥有一个.deb文件,您可以使用命令sudo dpkg -i (package / downloaded .deb file path)在Linux上安装Google Chrome.铬-可能-支持这种功能.据我所知,应该.

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:获取网站以直接打印到已定义的本地打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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