Does anyone know how to print receipt use Java? I have googled for a long time. It seems Java POS should be a good solution. I have a quick look at it and it looks need the printer's Java driver. My printer is a cheap one, support ESC, but only have Windows driver.
I also tried:
FileWriter out = new FileWriter("LPT1");
It does not work,
开发者_JS百科java.io.FileNotFoundException: lpt1 (The system cannot find the file specified)
Printable does not work neither.
Does any one know how to do this? Thanks.
Is the Java Print Service API of use ? If not, perhaps the javacomm package since you're writing to a serial port.
The proper syntax is as follows:
FileWriter out = new FileWriter("LPT1:");
There was a colon missing.
Does it happen to be an IP Printer? If so, they generally listen on port 9100, and you can just write to that directly (text data) and it will print. You'll want to look up appropriate escape sequences, to do various things (cut, for example).
The best way to handle these things is via JavaPOS APIs; but even then, you can still get stuck when the Maker of your hardware does not provide the appropriate drivers, in which case you are stuck at serial ports. Give JavaPOS a look, it might make your work very easy.
JavaPos Website
精彩评论