Sending common text / text directly to Epson dot matrix printer via USB using Java
Is there a way to send the encoded string "ESC" directly to an Epson dot matrix printer connected to USB using Java. I tried this using LPT1 port successfully. However, most of our customers are now using USB cables instead of the old parellel cables. The main problem I am facing is how to open a special USB port where the printer is connected as an output stream in Java. Thanks in advance for any advice and suggestions.
Since you are talking LPT1, I assume this is for Windows.
I don't see a 100% Java solution on this, you want to deal with hardware
JNI
You can use JNI to call some native language Windows DLLs (C / C ++ / Delphi) that exports one SendData function. You can prepare the data in a temporary file (arbitrary filename) and the DLL will send it to the printer and then delete it.
In Java, you can use load and loadlibrary to load DLL.
Use some ready-made solutions to convert it to USB / LPT
- Driver for your printer.
- NET USE command
- DOS2USB or DOS2PRN
a source to share
This is how it is done in Java:
PrintService pservice = ... // acquire print service of your printer
DocPrintJob job = pservice.createPrintJob();
String commands = "";
commands += "\u001B\u0045\u000A"; // plain
commands += "Hello ";
commands += "\u001B\u0045\u000D"; // bold
commands += "ESCP!";
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(commands.getBytes(), flavor, null);
job.print(doc, null);
Borrowed from: fooobar.com/questions/667532 / ...
Please note that on some operating systems, the printer must be configured as a source / shared printer . For USB printers, this often involves installing the USB driver and then adding a second printer with the same port but the original or generic driver.
a source to share