Remote print module in Java

試著忘記壹切 提交于 2020-02-02 11:37:06

问题


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

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.

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.

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.

Any ideas?


回答1:


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:

Taked from, 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) { 
    }
}



回答2:


That's why you have applets. But applets run in a security sandbox. However, if the right kind of privileges are given to the applet running in a webapp, it can open socket, write to files, write to serial port, etc.



来源:https://stackoverflow.com/questions/155740/remote-print-module-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!