Java 中的远程打印模块 [英] Remote print module in Java

查看:95
本文介绍了Java 中的远程打印模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序将支持基于网络的销售点界面.

I am working on an application that will sport a web-based point of sale interface.

销售点 PC(我现在不确定它是在 Linux 还是 Windows 上运行)必须有一个财务打印机连接到它,但与任何网络应用程序一样,它是处理所有内容的服务器.服务器和 PoS 机器都在同一个局域网上.

The point of sale PC (I am not sure as of now whether it will run on Linux or Windows) must have a fiscal printer attached to it, but like any web app, it is the server which processes all stuff. Both server and PoS machines are on the same LAN.

我必须实时发送销售数据,并通过使用串口的财务打印机,所以打印PDF甚至网页都不是一种选择.

I must send the sale data in real time, and via the fiscal printer which uses the serial port, so printing a PDF or even a web page is not an option.

有人告诉我,我可以让一个小应用程序侦听客户端上的 Web 服务,它反过来与打印机对话,而不是与服务器或浏览器对话,但我不知道如何去做.此外,我很可能需要听取任何打印机反馈(例如,由打印机生成的优惠券号)并将其交还给服务器.

I've been told I could have a little app listening on web services on the client, which in turn talks to the printer instead of the server or the browser, but don't have a clue how to do it. Also, I'll most likely need to listen to any printer feedback (coupon number, for instance, which is generated by the printer) and hand it back to the server.

有什么想法吗?

推荐答案

几年前我做过类似的事情.前.但在我的情况下,服务器和 PC 在同一个局域网中.你的 PoS 是否在局域网内?如果是这样,我会向您解释.

I did something similar to this a couple of yrs. ago. But in my case the server and the PC where in the same lan. Is your PoS within the lan? If so, I'll explain it to you.

同时,如果您涵盖了小应用程序",您可以查看以下内容:

In the mean time, if you have the "little app" covered you can take a look at the following:

http://java.sun.com/j2se/1.4.2/docs/api/javax/print/PrintService.html

打印服务有一种方法可以发现在它运行的机器上注册的打印机.因此,在您的应用程序上收到来自服务器的消息后,您只需执行类似于上面链接中显示的代码的操作:

The print service have a method to discover the printers registered within machine it is running on. So after you receive the message from the server on your app you just have to do something similar to the code shown in the link above:

取自,http://java.sun.com/j2se/1.4.2/docs/api/javax/print/PrintService.html

DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
PrintRequestAttributeSet aset = new HashPrintRequestHashAttributeSet();
aset.add(MediaSizeName.ISO_A4);
PrintService[] pservices =
             PrintServiceLookup.lookupPrintServices(flavor, aset);
if (pservices.length > 0) {
   DocPrintJob pj = pservices[0].createPrintJob();
   // InputStreamDoc is an implementation of the Doc interface //
   Doc doc = new InputStreamDoc("test.ps", flavor);
   try {
         pj.print(doc, aset);
    } catch (PrintException e) { 
    }
}

这篇关于Java 中的远程打印模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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