Reputation: 305
I am a complete newbie to kiosk printers.
I need to send a string from a java app to a zebra kr203 kiosk printer.
The machine is hooked up to a windows 7 pc and its drivers are installed. Printing test pages works fine.
I have also installed the setup utilities for the printer and they allow sending commands to it through EPL2 language. Again, I am completeley new to EPL2 but I have tried some example commands and nothing worked.
Can someone please write some basic java code to send a short string to the printer?
No GUI needed just a simple command line app.
EDIT: I found some code on google that gets the correct printService but it still won't print anything out.
EDIT NO. 2: I ended up using the Zebra SDK provided on their website. They keep code examples there which you can easily find by googling. I edited out the old code since it is useless.
Using the SDK and examples I figured out that the printer actually uses ZPL2 instead of EPL as I originally thought.
The SDK has its own API for sending commands at it works quite smoothly for me.
Upvotes: 0
Views: 3413
Reputation: 305
This is what I ended up using:
String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
com.zebra.sdk.comm.Connection myconnection = new com.zebra.sdk.comm.DriverPrinterConnection(defaultPrinter,1000,1000);
myconnection.open();
com.zebra.sdk.printer.ZebraPrinter myprinter = ZebraPrinterFactory.getInstance(myconnection);
String command = "^XA\n" +
"^FO50,50\n" +
"^A@N,20,20,E:TT0003M_.FNT\n" +
"^FDUplatili ste XXXX na račun XXXXXXXXXX^FS\n" +
"^FO50,150\n" +
"^A0,32,25\n" +
"^FD"+ date.toString()+ "^FS\n" +
"^FO50,250\n" +
"^A0,32,25^FDSlavnoska Avenija 19, 10000 Zagreb^FS\n" +
"^XZ";
myprinter.sendCommand(command);
myconnection.close();
Upvotes: 1
Reputation: 144
Do you have multiple printers to choose from...or just one printer?
private void printLabel() {
try{
FileOutputStream fos = new FileOutputStream("\\Your Printer Here");
PrintStream ps = new PrintStream(fos);
//try with the EPL commands or take a look at the ZPL programming guide
String commands = "N\n" +
"A50,50,0,2,2,2,N,\"" + label + "\"\n" +
"B50,100,0,1,2,2,170,B,\"" + label + "\"\n" +
"A50,310,0,3,1,1,N,\"" + czas + "\"\n" +
"P1\n";
ps.println(commands);
ps.print("\f");
ps.flush();
ps.close();
}catch(Exception e){
e.printStackTrace();
}
} `
Upvotes: 0