views:

875

answers:

2

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  A: 

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) { 
    }
}
OscarRyz
A: 
anjanb
Not really, because web page where the applet lives on, should be opened always. A background standalone app consuming the webservice can do the work.
OscarRyz